Alp*_*olf 12 python youtube-dl
我尝试按照教程从 youtube 下载视频:
import youtube_dl
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=Bdf-PSJpccM'])
Run Code Online (Sandbox Code Playgroud)
但我看到只有在使用带有选项的命令(在命令行中)时,-o我们才能更改输出视频名称。那么,如何添加嵌入在 python 脚本中的更改输出名称选项?我认为它应该添加到ydl_opts,但我不知道语法,有人可以帮忙吗?
MYG*_*YGz 17
像这样尝试:
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'])
Run Code Online (Sandbox Code Playgroud)
在 ydl_opts 中替换所需的文件名和文件路径。 file_path/file_name