This post describes how to download and convert Youtube videos to mp3, in Ubuntu Linux. Please note that this is not an encouragement to copyright infringement, I use these tools for downloading and listening to videos on my long commute with the London Underground, where no GSM or Wifi signal are available.
Requirements:
youtube-dl – “is a small command-line program to download videos from YouTube.com and a few more sites.”
ffmpeg – “is a complete, cross-platform solution to record, convert and stream audio and video.”, required by youtube-dl.
libavcodec-extra-53 – Libav codec library, required by youtube-dl for converting files to mp3.
Install:
sudo apt-get install youtube-dl
sudo apt-get install ffmpeg
sudo apt-get install libavcodec-extra-53
Script:
The following script (fetch.sh), will download videos based on URLs stored in a text file (tracks.lst):
#!/bin/bash tracks=() while read line do echo -e "Downloading '$line'..." youtube-dl -q --console-title --extract-audio --audio-format=mp3 -o "%(title)s.%(ext)s" $line done < tracks.lst
Usage:
Resulting files should be stored with the name [Youtube Title].mp3, residing in the same folder as the script.
NOTE: If you do not wish to convert files to MP3, remove the “–extract-audio –audio-format=mp3” parameters in the above script.