how to set up default download location in youtube-dl

后端 未结 6 1189
佛祖请我去吃肉
佛祖请我去吃肉 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:41

    I find a way to directly download files in Downloads folder. I search for long hours. I copied my entire function then you can understand the context around. Here is my code it will maybe helpful for someone:

    import os
    
    def download_audio(request):
      SAVE_PATH = '/'.join(os.getcwd().split('/')[:3]) + '/Downloads'
    
      ydl_opts = {
          'format': 'bestaudio/best',
          'postprocessors': [{
              'key': 'FFmpegExtractAudio',
              'preferredcodec': 'mp3',
              'preferredquality': '192',
          }],
          'outtmpl':SAVE_PATH + '/%(title)s.%(ext)s',
    
      }
    
      link = request.GET.get('video_url')
    
      with youtube_dl.YoutubeDL(ydl_opts) as ydl:
          ydl.download(["https://www.youtube.com/watch?v="+link])
    

    Tell me if there is a problem.

提交回复
热议问题