Skip to content

feat(commands): YT_DLP_COOKIES_PATH for YouTube auth bypass - #46

Merged
1Git2Clone merged 1 commit into
mainfrom
feat/yt-dlp-cookies
Jun 24, 2026
Merged

feat(commands): YT_DLP_COOKIES_PATH for YouTube auth bypass#46
1Git2Clone merged 1 commit into
mainfrom
feat/yt-dlp-cookies

Conversation

@1Git2Clone

Copy link
Copy Markdown
Owner

YouTube blocks downloads from datacenter IPs with a "Sign in to confirm you're not a bot" error. Adds an optional YT_DLP_COOKIES_PATH env var that passes --cookies to yt-dlp, allowing authentication via exported browser cookies.

Changes:

  • src/commands/util/download.rs — reads YT_DLP_COOKIES_PATH and passes --cookies to yt-dlp if set
  • .env.example — added YT_DLP_COOKIES_PATH with comment
  • .gitignore — added /cookies.txt
  • docs/download.md — new file with cookie export guide and alternatives considered
  • docs/configuration.md — updated to mention the new env var

Closes #45.

@1Git2Clone 1Git2Clone added enhancement New feature or request area: commands Discord slash commands labels Jun 24, 2026
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown

Greptile Summary

Adds an optional YT_DLP_COOKIES_PATH environment variable that passes --cookies <path> to yt-dlp, letting the bot authenticate via exported browser cookies to work around YouTube's datacenter-IP bot detection. Documentation, .env.example, and .gitignore are updated consistently.

  • src/commands/util/download.rs: builds the yt-dlp command into a mut cmd, then conditionally appends --cookies if the env var is set and non-empty — clean and correct. Also includes several unrelated cosmetic refactors (rfind, formatting) and a new .gitattributes file that are out of scope per the project's Surgical Changes rule.
  • docs/download.md: new file with a thorough cookie-export guide and a clear alternatives table — well-written and useful.
  • docs/configuration.md / .env.example: correctly extended to document the new optional variable.

Confidence Score: 5/5

Safe to merge — the core change is a small, opt-in env-var read that only affects users who explicitly set it, and the cookies path comes from operator-controlled config rather than user input.

The feature itself is minimal and correct: the env var is read at invocation time, the empty-string guard prevents an accidental --cookies "" being passed, and because the value comes from the operator's environment rather than Discord user input, there is no injection surface. The only comment is about unrelated cosmetic changes bundled into the diff.

No files require special attention.

Important Files Changed

Filename Overview
src/commands/util/download.rs Core feature change: reads YT_DLP_COOKIES_PATH at invocation time and appends --cookies to the yt-dlp command when set and non-empty. Also includes unrelated rfind refactor and cosmetic formatting changes out of scope for this task.
.env.example Adds commented-out YT_DLP_COOKIES_PATH example with helpful inline documentation linking to the yt-dlp FAQ.
.gitignore Adds /cookies.txt to gitignore to prevent accidental commit of the sensitive cookies file.
.gitattributes New file enforcing LF line endings — unrelated to this PR's stated scope.
docs/download.md New doc page explaining the YouTube bot-detection problem, cookie export workflow, and alternatives considered.
docs/configuration.md Updates the util-download runtime requirements note to mention the optional YT_DLP_COOKIES_PATH variable.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant U as User
    participant B as Bot
    participant E as Env
    participant Y as yt-dlp
    participant F as ffmpeg/ffprobe
    participant D as Discord

    U->>B: "/util download <url> [start] [end]"
    B->>B: validate_url() — allowlist check
    B->>B: validate_timecode() for start/end
    B->>B: acquire DOWNLOAD_SLOT permit
    B->>E: std::env::var("YT_DLP_COOKIES_PATH")
    alt cookies path set
        E-->>B: Ok(path)
        B->>Y: "yt-dlp --no-playlist ... --cookies <path> <url>"
    else not set or empty
        E-->>B: Err / empty
        B->>Y: "yt-dlp --no-playlist ... <url>"
    end
    Y-->>B: stdout: actual file path
    B->>F: ffprobe — probe duration
    F-->>B: duration (secs)
    alt start or end provided
        B->>F: ffmpeg trim → trimmed.mp4
    end
    alt file ≤ 8 MB
        B->>B: fs::copy to output.mp4
    else "file > 8 MB"
        B->>F: ffmpeg 2-pass encode → output.mp4
    end
    B->>D: upload output.mp4 as attachment
    D-->>U: Here's your clip (X.X MB)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant U as User
    participant B as Bot
    participant E as Env
    participant Y as yt-dlp
    participant F as ffmpeg/ffprobe
    participant D as Discord

    U->>B: "/util download <url> [start] [end]"
    B->>B: validate_url() — allowlist check
    B->>B: validate_timecode() for start/end
    B->>B: acquire DOWNLOAD_SLOT permit
    B->>E: std::env::var("YT_DLP_COOKIES_PATH")
    alt cookies path set
        E-->>B: Ok(path)
        B->>Y: "yt-dlp --no-playlist ... --cookies <path> <url>"
    else not set or empty
        E-->>B: Err / empty
        B->>Y: "yt-dlp --no-playlist ... <url>"
    end
    Y-->>B: stdout: actual file path
    B->>F: ffprobe — probe duration
    F-->>B: duration (secs)
    alt start or end provided
        B->>F: ffmpeg trim → trimmed.mp4
    end
    alt file ≤ 8 MB
        B->>B: fs::copy to output.mp4
    else "file > 8 MB"
        B->>F: ffmpeg 2-pass encode → output.mp4
    end
    B->>D: upload output.mp4 as attachment
    D-->>U: Here's your clip (X.X MB)
Loading

Reviews (2): Last reviewed commit: "feat(commands): add YT_DLP_COOKIES_PATH ..." | Re-trigger Greptile

Comment thread src/commands/util/download.rs
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/commands/util/download.rs 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@1Git2Clone
1Git2Clone force-pushed the feat/yt-dlp-cookies branch from d5c08d7 to 795be11 Compare June 24, 2026 09:15
YouTube blocks downloads from datacenter IPs with a 'Sign in to confirm
you're not a bot' error. Add an optional YT_DLP_COOKIES_PATH env var
that passes --cookies to yt-dlp, allowing authentication via exported
browser cookies.

Also:
- Add cookies.txt to .gitignore
- Add docs/download.md with export guide and alternatives considered
- Update docs/configuration.md to mention the new env var

Co-authored-by: DeepSeek V4 Pro <service@deepseek.com>
@1Git2Clone
1Git2Clone force-pushed the feat/yt-dlp-cookies branch from 795be11 to 59bba58 Compare June 24, 2026 09:16
@1Git2Clone
1Git2Clone merged commit a2a415b into main Jun 24, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: commands Discord slash commands enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

yt-dlp blocked by YouTube auth — add Cobalt backend as primary downloader

1 participant