stars
This commit is contained in:
1 parent
8647352d0f
commit
758defee99
7 files changed
+183
-52
No files matched your search
@@ -1,3 +1,4 @@
|
||||
from sqlalchemy import and_
|
||||
from app.core.models.node_storage import StoredContent
|
||||
from app.core.models.content.user_content import UserContent, UserAction
|
||||
from app.core.logger import make_log
|
||||
@@ -7,6 +8,9 @@ from app.core._keyboards import get_inline_keyboard
|
||||
from app.core.models.messages import KnownTelegramMessage
|
||||
from aiogram.types import URLInputFile, Message
|
||||
import json
|
||||
import urllib
|
||||
|
||||
from app.core.models.transaction import StarsInvoice
|
||||
|
||||
|
||||
class PlayerTemplates:
|
||||
@@ -55,8 +59,25 @@ class PlayerTemplates:
|
||||
local_content.meta['cover_cid'] = cover_content.cid.serialize_v2() if cover_content else None
|
||||
|
||||
local_content_cid = local_content.cid
|
||||
local_content_cid.content_type = 'audio/mpeg'
|
||||
local_content_url = f"{PROJECT_HOST}/api/v1/storage/{local_content_cid.serialize_v2(include_accept_type=True)}"
|
||||
local_content_url = f"{PROJECT_HOST}/api/v1.5/storage/{local_content_cid.serialize_v2()}"
|
||||
converted_content = content.meta.get('converted_content')
|
||||
if not converted_content:
|
||||
r = await tg_process_template(
|
||||
self, self.user.translated('p_playerContext_contentNotReady'),
|
||||
message_id=message_id,
|
||||
message_type='common'
|
||||
)
|
||||
return r
|
||||
|
||||
content_share_link = {
|
||||
'text': self.user.translated('p_shareLinkContext').format(title=content_metadata_json.get('name', "")),
|
||||
'url': f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}?start=C{content.cid.serialize_v2()}"
|
||||
}
|
||||
|
||||
preview_content = db_session.query(StoredContent).filter(
|
||||
StoredContent.hash == converted_content['low_preview']
|
||||
).first()
|
||||
local_content_preview_url = preview_content.web_url
|
||||
if content_type == 'audio':
|
||||
audio_title = content_metadata_json.get('name', "").split(' - ')
|
||||
if len(audio_title) > 1:
|
||||
@@ -65,15 +86,21 @@ class PlayerTemplates:
|
||||
|
||||
template_kwargs['title'] = audio_title[0].strip()
|
||||
template_kwargs['protect_content'] = True
|
||||
template_kwargs['audio'] = URLInputFile(local_content_url)
|
||||
template_kwargs['audio'] = URLInputFile(local_content_preview_url)
|
||||
if cover_content:
|
||||
template_kwargs['thumbnail'] = URLInputFile(cover_content.web_url)
|
||||
|
||||
if self.bot_id == 1:
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('shareTrack_button'),
|
||||
'switch_inline_query': f"C{content.cid.serialize_v2()}",
|
||||
}])
|
||||
inline_keyboard_array.append([
|
||||
{
|
||||
'text': self.user.translated('shareTrack_button'),
|
||||
'switch_inline_query': f"C{content.cid.serialize_v2()}",
|
||||
},
|
||||
{
|
||||
'text': self.user.translated('shareLink_button'),
|
||||
'url': f"https://t.me/share/url?text={urllib.parse.quote(content_share_link['text'])}&url={urllib.parse.quote(content_share_link['url'])}"
|
||||
}
|
||||
])
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('openTrackInApp_button'),
|
||||
'url': f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={content.cid.serialize_v2()}"
|
||||
@@ -90,7 +117,7 @@ class PlayerTemplates:
|
||||
elif content_type == 'video':
|
||||
# Processing video
|
||||
video_title = content_metadata_json.get('name', "")
|
||||
template_kwargs['video'] = URLInputFile(local_content_url)
|
||||
template_kwargs['video'] = URLInputFile(local_content_preview_url)
|
||||
template_kwargs['protect_content'] = True
|
||||
|
||||
if cover_content:
|
||||
@@ -99,10 +126,16 @@ class PlayerTemplates:
|
||||
|
||||
if self.bot_id == 1:
|
||||
# Buttons for sharing and opening in app
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('shareVideo_button'),
|
||||
'switch_inline_query': f"C{content.cid.serialize_v2()}",
|
||||
}])
|
||||
inline_keyboard_array.append([
|
||||
{
|
||||
'text': self.user.translated('shareVideo_button'),
|
||||
'switch_inline_query': f"C{content.cid.serialize_v2()}",
|
||||
},
|
||||
{
|
||||
'text': self.user.translated('shareLink_button'),
|
||||
'url': f"https://t.me/share/url?text={urllib.parse.quote(content_share_link['text'])}&url={urllib.parse.quote(content_share_link['url'])}"
|
||||
}
|
||||
])
|
||||
inline_keyboard_array.append([{
|
||||
'text': self.user.translated('openTrackInApp_button'),
|
||||
'url': f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={content.cid.serialize_v2()}"
|
||||
@@ -134,14 +167,24 @@ class PlayerTemplates:
|
||||
have_access = (
|
||||
(content.owner_address == user_wallet_address)
|
||||
or bool(self.db_session.query(UserContent).filter_by(owner_address=user_wallet_address, status='active', content_id=content.id).first())
|
||||
or bool(self.db_session.query(UserContent).filter(
|
||||
and_(
|
||||
StarsInvoice.user_id == self.user,
|
||||
StarsInvoice.content_hash == content['encrypted_content'].hash,
|
||||
StarsInvoice.paid == True
|
||||
)
|
||||
))
|
||||
)
|
||||
if not have_access:
|
||||
if have_access:
|
||||
full_content = self.db_session.query(StoredContent).filter_by(
|
||||
hash=content.meta.get('converted_content', {}).get('low') # TODO: support high quality
|
||||
).first()
|
||||
if content_type == 'audio':
|
||||
# Restrict audio to 30 seconds if user does not have access
|
||||
template_kwargs['audio'] = URLInputFile(local_content_url + '?seconds_limit=30')
|
||||
template_kwargs['audio'] = URLInputFile(full_content.web_url)
|
||||
elif content_type == 'video':
|
||||
# Restrict video to 30 seconds if user does not have access
|
||||
template_kwargs['video'] = URLInputFile(local_content_url + '?seconds_limit=30')
|
||||
template_kwargs['video'] = URLInputFile(full_content.web_url)
|
||||
|
||||
make_log("TG-Player", f"Send content {content_type} ({content_encoding}) to chat {self._chat_id}. {cd_log}")
|
||||
for kmsg in self.db_session.query(KnownTelegramMessage).filter_by(
|
||||
|
||||
Reference in new issue
Block a user