使用 python 使用 youtube-dl 下载时更改输出名称
Change the output name when download with youtube-dl using python
我尝试按照教程从 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
,但我不知道语法,有人可以帮忙吗?
这样试试:
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
补充一下@MYGz的回答,outtmpl
可以根据视频数据进行格式化。您可以在此处获取更多信息:https://github.com/rg3/youtube-dl/issues/5192#issuecomment-78843396.
我尝试按照教程从 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
,但我不知道语法,有人可以帮忙吗?
这样试试:
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
补充一下@MYGz的回答,outtmpl
可以根据视频数据进行格式化。您可以在此处获取更多信息:https://github.com/rg3/youtube-dl/issues/5192#issuecomment-78843396.