From 0f6c0fe09de2672d28e063e907a4a28f391f0480 Mon Sep 17 00:00:00 2001 From: user Date: Wed, 5 Feb 2025 11:00:07 +0300 Subject: [PATCH] try send cached video --- app/client_bot/routers/content.py | 8 ++++---- app/core/models/_telegram/templates/player.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/client_bot/routers/content.py b/app/client_bot/routers/content.py index 14ae750..352f75a 100644 --- a/app/client_bot/routers/content.py +++ b/app/client_bot/routers/content.py @@ -158,13 +158,13 @@ async def t_inline_query_node_content(query: types.InlineQuery, memory=None, use ) elif content_type_declared == 'video': content_list.append( - types.InlineQueryResultVideo( + types.InlineQueryResultCachedVideo( id=f"NC_{content.id}", - video_url=decrypted_content.web_url + '?seconds_limit=30', + video_file_id=encrypted_content.meta['telegram_file_cache'], title=title, caption=hashtags_str + user.translated('p_playerContext_preview'), - mime_type="video/mp4", - thumbnail_url='https://raw.githubusercontent.com/my-mirror/assets/refs/heads/main/video_icon.png', + # mime_type="video/mp4", + # thumbnail_url='https://raw.githubusercontent.com/my-mirror/assets/refs/heads/main/video_icon.png', parse_mode='html', reply_markup=get_inline_keyboard([ [{ diff --git a/app/core/models/_telegram/templates/player.py b/app/core/models/_telegram/templates/player.py index f99e310..c47af4f 100644 --- a/app/core/models/_telegram/templates/player.py +++ b/app/core/models/_telegram/templates/player.py @@ -5,7 +5,7 @@ from app.core._utils.tg_process_template import tg_process_template from app.core._config import PROJECT_HOST, CLIENT_TELEGRAM_BOT_USERNAME from app.core._keyboards import get_inline_keyboard from app.core.models.messages import KnownTelegramMessage -from aiogram.types import URLInputFile +from aiogram.types import URLInputFile, Message import json @@ -150,7 +150,7 @@ class PlayerTemplates: ).all(): await self.delete_message(kmsg.message_id) - return await tg_process_template( + r = await tg_process_template( self, text, message_id=message_id, **template_kwargs, keyboard=get_inline_keyboard([*inline_keyboard_array, *extra_buttons]) if inline_keyboard_array else None, message_type=f'content/{content_type}', @@ -158,5 +158,19 @@ class PlayerTemplates: content_id=content.id if content else None ) + if self.bot_id == 1: + 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, + } + + return r +