fix(youtube): correct extractor-args separator, soften worker recycling, retry video upload
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 1m53s

EXTRACTOR_ARGS used ':' instead of ';' between player_client and skip
fields, so yt-dlp parsed "android:skip=translated_subs" and "hls" as
bogus player_client values and silently fell back to the web client
only, which fails the n-challenge and returns no formats.

--max-requests=1 fully restarted the gunicorn worker after every
single request, opening a race window that could drop the response
connection right after a successful download; raised to 20 with
jitter to keep the periodic-recycle safety net without doing it on
every request.

reply_video() to Telegram had no retry, so a transient httpx
transport error during upload discarded an already-downloaded video;
added the same 3-attempt retry pattern already used for the
downloader services.
This commit is contained in:
vrubelroman 2026-06-30 20:24:46 +00:00
parent ab703e4bd6
commit 67dba21ff9
3 changed files with 29 additions and 18 deletions

42
bot.py
View file

@ -576,25 +576,37 @@ async def process_queue_item(item: QueueItem):
# Отправляем файл пользователю
await item.status_message.edit_text(get_text(item.locale, 'sending'))
video_file = open(video_path, 'rb')
caption = get_text(item.locale, 'caption', bot_username=TELEGRAM_BOT_USERNAME)
caption += f"\n\n{item.url}"
# Определяем имя файла для отправки
video_filename = Path(video_path).name
# Отправляем как видео со streaming — встроенный плеер Telegram
await item.original_message.reply_video(
video=video_file,
filename=video_filename,
caption=caption,
supports_streaming=True,
read_timeout=600,
write_timeout=600,
connect_timeout=60,
pool_timeout=60
)
video_file.close()
# Отправляем как видео со streaming — встроенный плеер Telegram.
# Загрузка большого файла в Telegram API иногда обрывается транспортной
# ошибкой httpx (ReadError/RemoteProtocolError) — ретраим, открывая файл заново.
send_retries = 3
for attempt in range(send_retries):
video_file = open(video_path, 'rb')
try:
await item.original_message.reply_video(
video=video_file,
filename=video_filename,
caption=caption,
supports_streaming=True,
read_timeout=600,
write_timeout=600,
connect_timeout=60,
pool_timeout=60
)
break
except Exception as send_error:
if attempt == send_retries - 1:
raise
logger.warning(f"Отправка видео: попытка {attempt + 1}/{send_retries} не удалась: {send_error}")
await asyncio.sleep((attempt + 1) * 2)
finally:
video_file.close()
# Увеличиваем счетчик скачанных видео
increment_downloads()