youtube-dl:在 Python 中将其作为库导入时,配置参数的名称是什么?

youtube-dl: What are the names of the config parameters when importing it as a library in Python?

youtube-dl python 库上似乎有 almost no documentation 而且 cli 工具的参数不翻译 1:1... 我能够在自述文件中链接的 YoutubeDL.py 中找到一些参数,但绝对不是全部。

例如,我不清楚如何将视频缩略图嵌入到我正在下载的视频文件中。使用 cli 工具,我可以使用 --embed-thumbnail,但是当我尝试在配置对象中使用它时,它不起作用。我什至没有收到错误

 ydl_opts = {
     'format': 'bestvideo[height<=480]+bestaudio[ext=m4a]/best', # works
     'embed-thumbnail': True, # not working
     'embedthumbnail': True, # not working
     'updatetime': False # works
 }
 youtube_dl.YoutubeDL(ydl_opts)

这是一个对我有用的 cli 示例:

youtube-dl --format "bestvideo[height<=480]+bestaudio[ext=m4a]/best" --embed-thumbnail https://www.youtube.com/watch?v=Co2KIYmaeTY

我在生成的 .mp4 文件上通过 运行 验证了它以提取缩略图:

AtomicParsley "thumbnail test-Co2KIYmaeTY.mp4" -E

这个文件是我得到的最接近的文件:https://github.com/rg3/youtube-dl/blob/master/youtube_dl/postprocessor/embedthumbnail.py

但我不确定该怎么做...

YoutubeDL.py 是否 列出 youtube-dl 的所有参数。 embed-thumbnailembedthumbnail 不起作用,因为它们不是 YoutubeDL 的有效选项,因此未列在选项列表中。但是,这些选项涵盖 "just" 下载。

许多效果由后处理器实现,即在下载完成后运行的代码。后处理器可以以新的方式组合,但如果您只想复制现有的 command-line 调用,请查看 main function 以了解 command-line 选项如何映射到后处理器和 YoutubeDL API 选项。例如,要将缩略图写入视频文件,您可以使用

from __future__ import unicode_literals
import youtube_dl

ydl_opts = {
    'format': 'bestvideo[height<=480]+bestaudio[ext=m4a]/best',
    'updatetime': False,
    'writethumbnail': True,
    'postprocessors': [{
        'key': 'EmbedThumbnail',
        'already_have_thumbnail': False,
    }],
}

with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc'])