【问题标题】:yt-dlp 'rate-limit' not throttiling speed in Python scriptyt-dlp 'rate-limit' 不限制 Python 脚本中的速度
【发布时间】:2021-12-20 14:17:08
【问题描述】:

我已将 yt-dlp 作为我的 Python 脚本的一部分实现,它运行良好,但我无法让速率限制功能正常工作。 如果您从 CLI 运行相同的命令,速率会被正确限制,有人能告诉我正确的语法吗?

我尝试了几种组合,例如 rate-limit、limit-rate 0.5m、500k、500KiB、500,但似乎都不起作用

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

    }

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

我在这里使用文档; https://github.com/yt-dlp/yt-dlp 但我很困惑,因为 CLI 命令有效,但嵌入式脚本版本无效,

我也尝试将 - 替换为 _ 但仍然没有效果,你有什么想法吗? ydl_opts 中的其他选项可以正常工作

希望我们能够解析正确的语法,而不必实现 Trickle 或限制套接字

如果你能帮忙,谢谢

【问题讨论】:

    标签: python bandwidth-throttling ytdl


    【解决方案1】:

    crawfr 的回答是正确的。但不是随机搜索源代码,所有选项都由 doscstrings 记录。 ratelimit可以在docstring of FileDownloader class中找到

    由于它在文档字符串中,如果您不想手动查看源文件,也可以使用 python help 来检索它

    >>> 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:写作作为答案,因为没有足够的声誉来发表评论

    【讨论】:

      【解决方案2】:

      查看source code,您会发现您要查找的选项称为ratelimit。它的值应该是一个浮点数:

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

      【讨论】:

      • 这非常有效,感谢您协助并与我分享此信息!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多