Skip to content

Add cookies to yt-dlp config and docker env#7510

Open
vinybrun wants to merge 3 commits intoChocobozzz:developfrom
vinybrun:add-yt-dlp-cookies
Open

Add cookies to yt-dlp config and docker env#7510
vinybrun wants to merge 3 commits intoChocobozzz:developfrom
vinybrun:add-yt-dlp-cookies

Conversation

@vinybrun
Copy link
Copy Markdown

@vinybrun vinybrun commented Mar 21, 2026

Description

Hello,

This PR addresses YouTube imports failing due to bot detection.

Specifically:

  • Adds a wrapper to pass a cookies file to yt-dlp/youtube-dl using the --cookies argument
  • Adds import/yt-dlp config to the Docker .env

For context, I work for a company that hosts PeerTube (and other software) for content creators, and we sync their content from YouTube to PeerTube for redundancy.

I found several related issues here (#5688, #6864, #6522, #6494) and on yt-dlp’s repository (yt-dlp/yt-dlp#16212, yt-dlp/yt-dlp#10128, yt-dlp/yt-dlp#16147).

After reviewing them, I tested a few approaches:

  • It seems YouTube changed their bot detection logic about two weeks ago. My IPs were quickly flagged, and reports of failures increased. I tried using a proxy on a VPS from another provider; it worked for about a day before being blocked as well.
  • In the following week, yt-dlp updated its challenge-solving dependency, which reportedly helped. However, by then all my IPs were blocked, and I didn’t want to keep rotating VPS proxies without knowing how long they would last.
  • PeerTube already pulls the latest yt-dlp version, which is great, but with blocked IPs, imports still failed.

I tried the approach suggested on this comment: #6522 (comment)

The wrapper worked, but since PeerTube overwrites the yt-dlp binary, it was only a temporary fix.

Then I created a patch in one of my instances to add the --cookies argument to the compiled PeerTube JS files, and it worked.

Since that approach was also temporary, and this may help others, I turned it into this PR.

Disclaimer: this PR was created with AI (ChatGPT Codex). I reviewed all files manually and made adjustments for maintainability and consistency. I also ran unit tests and tested imports with cookies in both a local dev environment and Docker; all succeeded.

Functionality: when cookies are enabled in the config, imports use yt-dlp with the --cookies argument pointing to the configured file.


I chose to create the cookies file at server startup, but I’m not sure if that’s the best approach.

I initially exposed the cookies file path, but ended up using a fixed path and creating the file automatically, so users only need to populate it.

I'm unsure about the paths and config names I chose (especially import in the storage folder). Those can be altered for better clarity if needed. Suggestions are welcome.

Known limitations:

  • Cookies expire, so they must be refreshed periodically (or synced via a script from a browser).
  • Cookies are applied instance-wide. This suits instances with disabled registration and tighter control over imports. This trade-off was discussed in yt-dlp rate limit #5688, but I think an instance-wide option is still useful given its low complexity compared to per-user solutions.
  • YouTube may take action against the account associated with the cookies (e.g., bans).
  • Cookies improve reliability but may not always guarantee successful imports.

This topic has been discussed for a while, so I expect others may have input. Happy to adjust anything if needed. Thanks.

Related issues

#5688, #6864, #6522, #6494

Has this been tested?

  • 👍 yes, I added tests to the test suite
  • 💭 no, because this PR is a draft and still needs work
  • 🙅 no, because this PR does not update server code
  • 🙋 no, because I need help

@vinybrun vinybrun changed the title Adds cookies to yt-dlp config and docker env Add cookies to yt-dlp config and docker env Mar 21, 2026
Copy link
Copy Markdown
Owner

@Chocobozzz Chocobozzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! From our experience using many ISP/residential for import.videos.http.proxies option helps a lot, but this method can also help to bypass blocked videos.

@vinybrun
Copy link
Copy Markdown
Author

Awesome! Thanks for the feedback, I'll implement the changes soon.

@vinybrun vinybrun force-pushed the add-yt-dlp-cookies branch from a66c26d to 2cfd8fd Compare April 8, 2026 08:13
@vinybrun
Copy link
Copy Markdown
Author

vinybrun commented Apr 8, 2026

Hi @Chocobozzz

I implemented the changes you pointed in your review, and they really improved the code quality. It looks much cleaner now. I tested again in a local install and docker and all looks good.

Also created a Merge Request for the docs on Framagit: https://framagit.org/framasoft/peertube/documentation/-/merge_requests/165

If I missed anything or if you have any other suggestions, just let me know and I'll be happy to adjust it.

@vinybrun vinybrun force-pushed the add-yt-dlp-cookies branch from 2cfd8fd to 0495c1e Compare April 8, 2026 09:09
@vinybrun vinybrun marked this pull request as draft April 8, 2026 09:22
@vinybrun vinybrun force-pushed the add-yt-dlp-cookies branch 3 times, most recently from d7b84f6 to 242a2a4 Compare April 8, 2026 10:05
@vinybrun vinybrun force-pushed the add-yt-dlp-cookies branch from 242a2a4 to 857a939 Compare April 8, 2026 10:11
@vinybrun vinybrun marked this pull request as ready for review April 8, 2026 10:12
@vinybrun vinybrun requested a review from Chocobozzz April 8, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants