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

2

18

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?

Verbal answered 20/12, 2016 at 10:59 Comment(0)
A
29

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

Aubervilliers answered 20/12, 2016 at 11:10 Comment(2)
Btw, can you give me the link of the doc talk about function syntax?Verbal
@Verbal It was right there from where you picked the example. github.com/rg3/youtube-dl/blob/master/youtube_dl/…Aubervilliers
E
1

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.

Expansion answered 29/6, 2018 at 15:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.