edit player ui globally

This commit is contained in:
user 2025-05-31 23:45:02 +03:00
parent 27dc827880
commit 58eca166db
1 changed files with 7 additions and 70 deletions

View File

@ -58,19 +58,6 @@ class PlayerTemplates:
except BaseException as e: except BaseException as e:
cd_log += f"Can't get cover content: {e}. " cd_log += f"Can't get cover content: {e}. "
cover_content = None cover_content = None
local_content.meta['cover_cid'] = cover_content.cid.serialize_v2() if cover_content else None
local_content_cid = local_content.cid
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 = { content_share_link = {
'text': self.user.translated('p_shareLinkContext').format(title=content_metadata_json.get('name', "")), 'text': self.user.translated('p_shareLinkContext').format(title=content_metadata_json.get('name', "")),
@ -78,36 +65,9 @@ class PlayerTemplates:
} }
if user_existing_license: if user_existing_license:
content_share_link['url'] = f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={user_existing_license.onchain_address}" content_share_link['url'] = f"https://t.me/{CLIENT_TELEGRAM_BOT_USERNAME}/content?startapp={user_existing_license.onchain_address}"
preview_content = db_session.query(StoredContent).filter(
StoredContent.hash == converted_content['low_preview']
).first()
if preview_content.filename.split('.')[-1] in ['mov', 'mp4']:
content_type = 'video'
local_content_preview_url = preview_content.web_url if cover_content:
if content_type == 'audio': template_kwargs['photo'] = URLInputFile(cover_content.web_url)
audio_title = content_metadata_json.get('name', "").split(' - ')
if len(audio_title) > 1:
template_kwargs['performer'] = audio_title[0].strip()
audio_title = audio_title[1:]
template_kwargs['title'] = audio_title[0].strip()
template_kwargs['protect_content'] = True
template_kwargs['audio'] = URLInputFile(local_content_preview_url)
if cover_content:
template_kwargs['thumbnail'] = URLInputFile(cover_content.web_url)
elif content_type == 'video':
# Processing video
video_title = content_metadata_json.get('name', "")
template_kwargs['video'] = URLInputFile(local_content_preview_url)
template_kwargs['protect_content'] = True
if cover_content:
# Add thumbnail if cover content is available
template_kwargs['thumbnail'] = URLInputFile(cover_content.web_url)
else:
local_content = None
if not local_content: if not local_content:
text = self.user.translated('p_playerContext_unsupportedContent').format( text = self.user.translated('p_playerContext_unsupportedContent').format(
@ -117,19 +77,11 @@ class PlayerTemplates:
inline_keyboard_array = [] inline_keyboard_array = []
extra_buttons = [] extra_buttons = []
else: else:
text = content_metadata_json.get('description').strip() text = f"""<b>{content_metadata_json.get('name', 'Unnamed')}</b>
have_access = ( {content_metadata_json.get('description').strip()}
(content.owner_address == user_wallet_address)
or bool(user_existing_license) <code><a href="{content_share_link['url']}">🌐 Открыть на MY</a></code>"""
or bool(self.db_session.query(StarsInvoice).filter(
and_(
StarsInvoice.user_id == self.user.id,
StarsInvoice.content_hash == content.hash,
StarsInvoice.paid == True
)
).first())
)
make_log("TG-Player", f"Send content {content_type} ({content_encoding}) to chat {self._chat_id}. {cd_log}") 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( for kmsg in self.db_session.query(KnownTelegramMessage).filter_by(
@ -141,26 +93,11 @@ class PlayerTemplates:
await self.delete_message(kmsg.message_id) await self.delete_message(kmsg.message_id)
r = await tg_process_template( r = await tg_process_template(
self, text + '\n\n' + f"""<a href="{content_share_link['url']}"><code>🌐 Открыть на MY</code></a>""", message_id=message_id, **template_kwargs, self, text, message_id=message_id, **template_kwargs,
keyboard=get_inline_keyboard([*inline_keyboard_array, *extra_buttons]) if inline_keyboard_array else None, keyboard=get_inline_keyboard([*inline_keyboard_array, *extra_buttons]) if inline_keyboard_array else None,
message_type=f'content/{content_type}', message_type=f'content/{content_type}',
message_meta={'content_sha256': content_meta['hash']} if local_content else {}, message_meta={'content_sha256': content_meta['hash']} if local_content else {},
content_id=content.id if content else None content_id=content.id if content else None
) )
if self.bot_id == 1:
if content.type == 'onchain/content':
if content_type == 'audio':
content.meta = {
**content.meta,
'telegram_file_cache': r.audio.file_id,
}
elif content_type == 'video':
content.meta = {
**content.meta,
'telegram_file_cache': r.video.file_id,
}
self.db_session.commit()
return r return r