Search code examples
pythonbandwidth-throttlingytdl

yt-dlp 'rate-limit' not throttiling speed in Python script


I have implemented yt-dlp as part of my Python script, it works well, but I am unable to get the rate-limit feature to work. If you run the same command from the CLI the rate is limited correctly, is anyone able to tell me the correct syntax?

I have tried several combinations such as rate-limit, limit-rate 0.5m, 500k, 500KiB, 500, and none seem to work

        ydl_opts = {
        'limit-rate': '500k',

    }

    with yt_dlp.YoutubeDL(ydl_opts) as ydl:
        ydl.download([link]) 

I am using the docs here; https://github.com/yt-dlp/yt-dlp But am confused as the CLI command works but not the embedded script version,

I also tried replacing - with _ but still to no effect, do you have any ideas? Other options in the ydl_opts work without issue

Hopefully we can resolve the correct syntax rather than having to implement Trickle or throttling the socket.


Solution

  • Looking at the source code you'll find that the option you're looking for is called ratelimit. Its value should be a float:

    ydl_opts = {
            'ratelimit': 500000
        }
    
    with yt_dlp.YoutubeDL(params=ydl_opts) as ydl:
        ydl.download([link])