Skip to content

Try yt-dlp cookie-free first; use cookies only as a fallback - #147

Merged
prekabreki merged 2 commits into
mainfrom
fix/145-cookies-as-fallback
Dec 4, 2026
Merged

prekabreki merged 2 commits into
mainfrom
fix/145-cookies-as-fallback

Conversation

@prekabreki

Copy link
Copy Markdown
Owner

Why

With --cookies, yt-dlp drops every client whose SUPPORTS_COOKIES is false. visionos is one of them, and it is the only client that serves YouTube's HLS formats. So loading cookies.txt silently hid 617 (VP9 1080p60, 7547k) and left 303 (3191k) as the best 1080p60 stream.

From yt-dlp 2026.11.23's _get_requested_clients:

_DEFAULT_CLIENTS = ('tv_samsung', 'visionos')
_DEFAULT_AUTHED_CLIENTS = ('tv_samsung', 'web_embedded', 'web')
visionos {'SUPPORTS_COOKIES': False, ...}

Adding player_client=visionos cannot fix it, because yt-dlp removes cookie-unsupported clients whenever it is authenticated.

What

Cookies are now a fallback, never the first try:

  • ytdlp._run_probe() runs a captured probe cookie-free. It retries once with cookies only when an ERROR: line matches _COOKIE_WALL_MARKERS (sign in, age gate, bot check, members-only, private). /video-info's flat probe and _get_formats use it.
  • fetch_item wraps its download in the same two-attempt loop and logs YouTube wants a signed-in viewer — retrying with cookies.
  • Only ERROR: lines count, so a title or WARNING mentioning "sign in" never triggers a retry.

Trade-off, chosen deliberately: YouTube Premium enhanced-bitrate formats are no longer offered automatically when cookies are loaded.

Verify

  • .venv/Scripts/python.exe -m unittest discover -s tests → OK
  • New tests/test_cookie_fallback.py (10 tests, fake yt-dlp that refuses cookie-free calls when wall is set).
  • Mutations: restoring cookies-first ordering fails 7 tests; disabling the download retry fails test_download_behind_a_cookie_wall_retries_with_cookies.
  • Live: _get_formats("…tlaxhiJ_l5U") with a cookies file present now lists 1080p60 ~7546k (617) and ~8977k (312).

Not verified live

The cookie-wall retry against a real age-gated video. The only cookie file at hand is no longer signed in, so that path is covered by the fake only. Review should try one age-restricted video with fresh cookies.

Closes #145

prekabreki and others added 2 commits December 4, 2026 12:11
With --cookies, yt-dlp drops every client that does not support cookies, including visionos, the only one that serves YouTube's high-bitrate HLS formats. A loaded cookies.txt therefore silently hid 617 (VP9 1080p60, 7547k) and left 303 (3191k).

Every yt-dlp call now runs cookie-free first and retries once with cookies only when an ERROR line says YouTube wants a signed-in viewer (sign in, age gate, bot check, members-only, private). Covers the /video-info flat probe, _get_formats and the fetch_item download.

Closes #145

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@prekabreki
prekabreki force-pushed the fix/145-cookies-as-fallback branch from 09aba03 to 930f282 Compare December 4, 2026 11:11
@prekabreki
prekabreki merged commit 2d1c81f into main Dec 4, 2026
8 checks passed
@prekabreki
prekabreki deleted the fix/145-cookies-as-fallback branch December 4, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep HLS formats visible when cookies are loaded

1 participant