Implement distributed rate limiting for downloads#357
Merged
Conversation
Amdrel
commented
Apr 2, 2026
Comment on lines
+39
to
+47
| RATE_LIMITED_DOMAINS = { | ||
| "youtube": { | ||
| "youtube.com", | ||
| "youtube-nocookie.com", | ||
| "youtubekids.com", | ||
| "youtu.be", | ||
| "youtube.googleapis.com", | ||
| }, | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
I couldn't find a way to use the extractor since that appears to be determined after the params are created and sent to yt-dlp, so this is a bit of a hack. I'm open to replacing this if there's a better way.
don-vip
approved these changes
Apr 2, 2026
Collaborator
|
Nice! Let's see if it helps. At least it won't hurt :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This patch aims to help reduce the risk of blocks from YouTube (see #320) by restricting video2commons from performing concurrent downloads of videos from YouTube and introducing a delay between requests. Concurrent downloads are restricted by using a lock stored in Redis that allows only one worker at a time to download videos.
Note: It seems the block is active again so we won't be able to see how successful this patch is until the existing one expires.
Changes
YoutubeDLRateLimitedthat wrapsyt_dlp.YoutubeDLlogging.basicConfig(level=logging.INFO)to the worker and flask app since logging wasn't setup and having the diagnostic information for concurrent locks might be useful if we run into any issuesDeployment
This change affects both the workers and the flask application, so both would need to be redeployed.
Testing
I've tested this patch against a couple of playlists (no larger than a dozen videos) and files with large amounts of subtitles using multiple workers, and the lock seemed to work fine. You can confirm the lock is working from the frontend if you see tasks being held up by "Creating YoutubeDL instance".
In the screenshot the first task is downloading a video (with the lock), the second is transcoding one, and the third is waiting for the lock to be released. It's important to note that the lock doesn't prevent other encoding tasks from running as it's released the moment the YouTube API is no longer in use.