Change the output name when download with youtube-dl using python

做~自己de王妃 提交于 2019-12-10 18:19:35

问题


I tried to follow the tutorial to download a video from youtube:

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

But i see only when using the command(in command line) with option -o we can change the output video name. So, how to add change output name option embedded in python script? I think it should be add to ydl_opts, but i don't know the syntax, can anybody help?


回答1:


Try like this:

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'])

Substitute the desired filename and filepath in ydl_opts. file_path/file_name




回答2:


Just complementing @MYGz answer, the outtmpl can be formatted according to the video data. You can get more information here: https://github.com/rg3/youtube-dl/issues/5192#issuecomment-78843396.



来源:https://stackoverflow.com/questions/41240726/change-the-output-name-when-download-with-youtube-dl-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!