how to set up default download location in youtube-dl

后端 未结 6 1226
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 09:16

how can I set default download location in youtube-dl so that everything that I download with youtube-dl goes into that default directory?

6条回答
  •  天命终不由人
    2021-01-30 09:37

    Here is the complete solution I use:

    from youtube_dl import YoutubeDL
    ydl_opts = {
       'format': 'best',
       'outtmpl': 'DIR-PATH-HERE%(title)s'+'.mp4',
       'noplaylist': True,
       'extract-audio': True,
    }
    
    video = "https://www.youtube.com/watch?v=SlPhMPnQ58k"
    with YoutubeDL(ydl_opts) as ydl:
       info_dict = ydl.extract_info(video, download=True)
       video_url = info_dict.get("url", None)
       video_id = info_dict.get("id", None)
       video_title = info_dict.get('title', None)
       video_length = info_dict.get('duration')
    
    # print(video_title)
    

提交回复
热议问题