Save MP3 to a specific directory using youtube_dl

Asked

Viewed 64 times

0

Hello! As said in the title, I’m wanting save the audio I’ll download to a specific folder from my desktop using youtube_dl, but I haven’t found a clear alternative.

The directory I will use in the case is this: C: Users jenka Desktop Work Sources

Does anyone have any solution?

import youtube_dl
import pytube

videoORaudio = input('Deseja baixar em MP3 ou Video? [1] para MP3 e [2] para Vídeo. -> ')

if videoORaudio == '1':
   video_url = input("Coloque o link do vídeo abaixo: ")
   video_info = youtube_dl.YoutubeDL().extract_info(url=video_url, download=False)

filename = f"{video_info['title']}.mp3"
options = {
    'format' : 'bestaudio/best',
    'keepvideo': False,
    'outtmpl': filename,
    'postprocessors': [{
        'key': 'FFmpegExtractAudio',
        'preferredcodec': 'mp3',
        'preferredquality': '192'
    }]

}
with youtube_dl.YoutubeDL(options) as ydl:
    ydl.download([video_info['webpage_url']])

1 answer

1


There are at least two ways to do this. One is by using the module itself youtube_dl. Just change the argument value outtmpl of filename for 'PATH%(title)s'+'.mp3'. Where PATH is the address you want to save the file. That is, C:\Users\jenka\Desktop\Trabalho\Sources, in your case.

Another way is to simply change the working directory from within the program using os.chdir

To do this, add the following lines at the top of the file:

import os
os.chdir("C:\Users\jenka\Desktop\Trabalho\Sources")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.