AlphaWolf
AlphaWolf

Reputation: 405

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?

Upvotes: 18

Views: 23789

Answers (2)

Cleber Alcântara
Cleber Alcântara

Reputation: 433

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.

Upvotes: 1

Mohammad Yusuf
Mohammad Yusuf

Reputation: 17064

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

Upvotes: 30

Related Questions