Skip to content

Add --cookies-from-browser flag for login-walled sources#21

Open
asayeed95 wants to merge 1 commit into
bradautomates:mainfrom
asayeed95:feat/cookies-from-browser
Open

Add --cookies-from-browser flag for login-walled sources#21
asayeed95 wants to merge 1 commit into
bradautomates:mainfrom
asayeed95:feat/cookies-from-browser

Conversation

@asayeed95

Copy link
Copy Markdown

Summary

Surfaces yt-dlp's --cookies-from-browser flag through /watch so login-walled sources work without dropping out to a manual yt-dlp invocation. Instagram Reels, private YouTube videos, and some X posts currently fail with Requested content is not available, rate-limit reached or login required — this PR makes the documented yt-dlp workaround available as a first-class flag.

Off by default. Public sources are byte-identical to current behavior.

Changes

  • scripts/watch.py — new --cookies-from-browser BROWSER argparse flag, passed through to download().
  • scripts/download.pydownload_url() and download() accept a cookies_from_browser kwarg and inject --cookies-from-browser <value> into the yt-dlp argv. The kwarg is rejected if it starts with - to defend against accidental flag injection. The CLI entry point accepts an optional 3rd positional arg for parity.
  • SKILL.md — documents the new flag, updates the "Download fails" failure-mode recipe to point at it as the documented retry path, and discloses in the Security & Permissions section that cookies are read transiently by yt-dlp (never written to disk, logged, or sent anywhere except the URL's host).
  • CHANGELOG.md[Unreleased] entry.

Security notes

  • The value is appended to the yt-dlp argv as a single argument (not shell-interpolated), so subprocess injection isn't a concern.
  • Values starting with - are rejected before invocation, so a caller can't sneak in something like --config-location /etc/passwd as the "browser name."
  • The flag forwards BROWSER[+KEYRING][:PROFILE][::CONTAINER] verbatim — yt-dlp does its own validation of browser names and rejects unknown ones with a clear error.
  • yt-dlp reads cookies from the browser's existing cookie store transiently. They're not copied into out_dir, not written to logs, not exfiltrated. The user remains signed in to the platform afterwards.

Test plan

  • python3 scripts/watch.py --help shows the new flag with full help text
  • download_url(..., cookies_from_browser='--config-location') raises SystemExit before invoking yt-dlp (flag-injection guard)
  • End-to-end against https://www.instagram.com/reel/DX9k8WDPZ2D/: default path fails with "login required" (current behavior); retry with --cookies-from-browser chrome succeeds and produces an mp4 + audio that the rest of the watch pipeline consumes normally (60 frames extracted, Whisper/Groq transcription returned 28 segments)
  • Public source without the flag: unchanged behavior

Why this is in scope for the skill

The existing "Download fails" recipe in SKILL.md currently tells the agent to give up on login-required content:

If it's a login-required or region-locked video, tell the user plainly; do not keep retrying.

That's the right behavior when there's no escape hatch — but yt-dlp itself documents --cookies-from-browser as the canonical workaround. Promoting it to a /watch flag means the agent has the same retry option a human running yt-dlp directly would have, with the security tradeoffs spelled out upfront.

🤖 Generated with Claude Code

yt-dlp can read existing browser session cookies via --cookies-from-browser
BROWSER[+KEYRING][:PROFILE][::CONTAINER]. Surface that as a /watch flag so
Instagram Reels, private YouTube videos, and some X posts work without a
manual yt-dlp invocation. Off by default — public sources are unchanged.

- watch.py: new --cookies-from-browser BROWSER argparse flag, passed
  through to download().
- download.py: download_url() / download() accept cookies_from_browser
  kwarg and inject "--cookies-from-browser <value>" into the yt-dlp argv.
  Rejects values starting with "-" to defend against accidental flag
  injection. CLI entry point accepts an optional 3rd positional arg for
  parity.
- SKILL.md: documents the new flag, updates the "Download fails" recipe
  to point at it as the documented retry path for login-required sources,
  and discloses in the Security & Permissions section that cookies are
  read transiently by yt-dlp — never written, logged, or sent anywhere
  except the URL's host.
- CHANGELOG.md: [Unreleased] entry.

Tested end-to-end on https://www.instagram.com/reel/DX9k8WDPZ2D/ — IG
blocked the default download path with "login required", retry with
--cookies-from-browser chrome succeeded and produced an mp4 + audio that
the rest of the watch pipeline consumed normally.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

1 participant