Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 560
AlphaWolf Avatar asked Dec 20 '16 10:12

AlphaWolf


1 Answers

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

like image 65
Mohammad Yusuf Avatar answered Oct 14 '22 10:10

Mohammad Yusuf