fix(youtube): retry without cookies on any yt-dlp failure, not just cookie-worded errors
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 50s

YouTube's SABR-only streaming rollout produces errors like "Signature
solving failed" / "Requested format is not available" that don't
mention cookies, so the existing no-cookies fallback never triggered.
Cookies also disable the android client, which is often the only one
still returning usable formats under this restriction.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-07-08 10:55:06 +00:00
parent d5201df802
commit 72ba00bdcd

View file

@ -405,9 +405,11 @@ def download_youtube_video(url: str, max_retries: int = 3, format_id: str | None
stderr = result.stderr.strip()[-800:]
logger.error(f"[DOWNLOAD] Попытка {attempt + 1}: yt-dlp failed: {stderr[:300]}")
# Try without cookies on cookies-related errors
if ('cookies' in stderr.lower() or 'bot' in stderr.lower() or 'sign in' in stderr.lower()) \
and '--cookies' in ' '.join(cmd):
# Пробуем без cookies при любой ошибке, а не только по ключевым словам:
# cookies отключают клиент "android" (см. "does not support cookies"),
# который часто остаётся единственным, кто отдаёт форматы при SABR-only
# ограничениях YouTube — так что без cookies шанс скачать выше почти всегда.
if '--cookies' in ' '.join(cmd):
logger.warning("[DOWNLOAD] Пробуем без cookies")
cmd_no_cookies = [a for i, a in enumerate(cmd) if a != '--cookies' and cmd[i-1] != '--cookies']
try: