0
votes

I like downloading YouTube videos and having mp3 versions in a subfolder to play on my phone during work.

Is it possible to call youtube-dl and download videos (from a playlist, with archive...) and save the MP3 extraction to a subfolder titled "MP3".

youtube-dl --download-archive "F:\Videos\Online Videos\Comics
Explained\Marvel Major Storylines (Constantly Updated)\Marvel Major
Storylines Archive.txt"
"https://www.youtube.com/playlist?list=PL9sO35KZL50yZh5dXW-7l93VZp7Ct4vYA"
-o "F:\Videos\Online Videos\Comics Explained\%(playlist_title)s\%(title)s.%(ext)s" -f
"bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
--ffmpeg-location "H:\Documents\FFMpeg\bin"

Then -x --audio-format mp3 --audio-quality 320k

But - I want the audio to output to:

"F:\Videos\Online Videos\Comics Explained\%(playlist_title)s\MP3\%(title)s.%(ext)s"
1
I'm close to completing some code for this, but can't output individual video urls with youtube_dl.YoutubeDL(ydl_opts) as ydl: ''' Code here should list urls of each video as vLinks variable ''' for vLink in vLinks: info_dict = ydl.extract_info(link, download=False) video_title = info_dict.get('title', None) playlist_index = info_dict.get('playlist_index', None) playlist = info_dict.get('playlist', None) uploader = info_dict.get('uploader', None) print(video_title) - Stack Johan

1 Answers

2
votes

There are multiple ways to do that:

  • Do the audio converting yourself, by invoking --exec with a script of yours that creates the necessary directories and then calls avconv, ffmpeg, vlc, or so.
  • Run youtube-dl twice with different parameters - once for video, once for audio. You'll download a little bit more data, but in many cases (especially when you download from YouTube instead of other sites) only the audio will be downloaded twice, the video only once.
  • Run youtube-dl twice with the same -o parameters: Once to download the files (pass in -k to keep the originals in your case), once to convert to mp3. In most cases, no additional download will be necessary the second time. Afterwards, write a small script that moves the mp3 files to the correct direction and cleans up.