0

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"
Stack Johan
  • 379
  • 1
  • 6
  • 23
  • 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 May 11 '17 at 01:40

1 Answers1

2

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.
  • I've been working on this and I'm nearly finished with the main bit of downloading videos and making the directories and moving the files, but I've been using extract_info for dynamic folder naming - and discovered this doesn't work with playlists. I need to get info from each video in the playlist. I've added a comment to explain more... – Stack Johan May 11 '17 at 01:36
  • `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 May 11 '17 at 01:40
  • @StackJohan You seem to have a new question. Feel free to ask it, well, [as a new question](http://stackoverflow.com/questions/ask). Make sure to include the [entire, complete, full code](https://stackoverflow.com/help/mcve). I have no idea what `vLinks` is, but if you want to download a playlist, just call youtube-dl with that playlist ID. –  May 11 '17 at 07:28
  • Thanks. Here's a detailed question with the full code >> http://stackoverflow.com/questions/43910501/how-do-i-retrieve-individual-video-urls-from-a-playlist-using-youtube-dl-within – Stack Johan May 11 '17 at 08:40