4

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.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
crawf
  • 75
  • 6

2 Answers2

1

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]) 
Tranbi
  • 11,407
  • 6
  • 16
  • 33
1

crawfr's answer is correct. but instead of randomly searching through the source code, all the options are documented by doscstrings. ratelimit can be found in the docstring of FileDownloader class

Since it is in the docstring, you can also use the python help to retrieve this if you don't want to manually go through the source files

>>> from yt_dlp import FileDownloader
>>> help(FileDownloader)
Help on class FileDownloader in module yt_dlp.downloader.common:

class FileDownloader(builtins.object)
 |  FileDownloader(ydl, params)
 |
 |  File Downloader class.
...
 |  ratelimit:          Download speed limit, in bytes/sec.
...

PS: Writing as answer since not enough reputation to comment

pukkandan
  • 36
  • 4