Recently I have had to download a large number of videos off the web for the purpose of archiving and transcoding. There are a lot of software products that do this but since I had to download hundreds of them at a time I decided to look into something on the command line so I could get it to download them all for me.
youtube-dl – This little program is what I ended up using and I have found it to be more than sufficient for my needs. If you ever needed to rip a video off of the web or to extract just the audio stream (just the music!) this tool handles it all. Despite it’s name, it works for what seems like hundreds of different websites, is free and open source and also has ways of handling generic video on websites as well.
- Lets install it through homebrew for ease:
brew install youtube-dl
- Go ahead and test it out by downloading a video:
youtube-dl -f bestvideo+bestaudio/best -ci http://www.dailymotion.com/video/x5f0hub
- The “
-f bestvideo+bestaudio/best” sets the video and audio formats to the very best. This is useful on sites which allow variable “quality” settings.
- The “
-ci” enables “continuation” which means you can resume a broken/partial download and the “
i” is to ignore errors and continue on.
- Here is another great option/argument: “
-a“, it will read a list of URLs from a file that you specify and download them each one at a time:
youtube-dl -f bestvideo+bestaudio/best -cia batchlist.txt
- Now for a command line to rip the audio stream out to an mp3 file of the highest possible quality:
youtube-dl --audio-format mp3 --audio-quality 0 -cix https://www.youtube.com/watch?v=TWYcSBHfPTQ
- Here is the YouTube title as above but with just the shorter ID instead of the entire URL. It also encodes to 128k AAC and selects the best quality audio to start with and includes the -ci options mentioned above:
youtube-dl -f bestaudio/best -cix --audio-format aac --audio-quality 128K TWYcSBHfPTQ
- Here is another good example for downloading the subtitles file and embedding it into the resulting video:
youtube-dl -f bestvideo+bestaudio -ci --sub-lang en --write-sub
--embed-subs --add-metadata --recode-video mp4
27/11/17 – UPDATE: I just tried to rip a video from Youku and youtube-dl threw up an error, advising that I either report it as a bug or update my youtube-dl installation. I choose to update it but homebrew still has an older version. So I ran the following to update it to the latest version and it was able to rip from Youku.
sudo chmod 777 /usr/bin/local/youtube-dl