【问题标题】:Change the output name when download with youtube-dl using python使用 python 使用 youtube-dl 下载时更改输出名称
【发布时间】:2023-03-29 18:57:01
【问题描述】:

我尝试按照教程从 youtube 下载视频:

import youtube_dl
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=Bdf-PSJpccM'])

但我只有在使用带有选项-o 的命令(在命令行中)时才能看到我们可以更改输出视频名称。那么,如何在 python 脚本中添加更改输出名称选项? 我认为应该添加到ydl_opts,但我不知道语法,有人可以帮忙吗?

【问题讨论】:

    标签: python youtube-dl


    【解决方案1】:

    试试这样:

    import youtube_dl
    ydl_opts = {'outtmpl': 'file_path/file_name'}
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download(['https://www.youtube.com/watch?v=Bdf-PSJpccM'])
    

    在 ydl_opts 中替换所需的文件名和文件路径。 file_path/file_name

    【讨论】:

    【解决方案2】:

    只是补充@MYGz的答案,outtmpl可以根据视频数据进行格式化。您可以在这里获取更多信息:https://github.com/rg3/youtube-dl/issues/5192#issuecomment-78843396。

    【讨论】:

      猜你喜欢
      • 2015-12-23
      • 1970-01-01
      • 1970-01-01
      • 2020-09-05
      • 1970-01-01
      • 2014-03-28
      • 1970-01-01
      • 2015-02-12
      相关资源
      最近更新 更多