leponceau.org

Programming And Stuff, You Know The Thing…

Youtube Downloads Made Easy

Posted at — Feb 3, 2019

There is an actually working, well-maintained open-source Youtube video downloader: youtube-dl (github). It even features downloading all videos of a given playlist or page (though it currently aborts when there is an error with a specific video, but you can restart at an arbitrary position)! Also, you can tell it to create metadata from the video’s title, ie. to convert a complete Youtube playlist to mp3 files.

Example script:

# ./dl
./youtube-dl -x --audio-format mp3 --audio-quality 112K \
    --metadata-from-title "(?P<artist>.+?) - (?P<title>.+)" \
    --add-metadata --embed-thumbnail --playlist-start "$@"

Then run that script with two params:

./dl $listOffset $playlistUrl

The natural friend of youtube-dl is libav. If you don’t specify an audio format, youtube-dl will simply extract the audio track with the -x option. Futher manual processing can look like this:

# cygwin on Windows
for f in *.m4a *.opus; do avconv -i "$f" -b 256k "E:\\mp3\\${f%.*}.ogg"; done

If your downloaded media has a too large file size, try the avconv.split.sh script to split it up. You might need to change it a little to adapt to your situational needs.