Handy youtube-dl

Sometime back I was taking an online, self-paced course for learning a new technology. The format of the course was particularly interesting since it had videos of about 5-7 mins of quick conceptual discussion followed by a programming excercise and solution discussion video. The idea was to see the video, understand the concept, do a lab exercise and check answers again on video. This was great as long as I was taking the course, but I soon realized that once the course is over, the tutorials may not be available any more and I should make some effort to download them for future reference. Downloading them individually was very dull and painful. So I kept wondering what more could be done. The course got over and so did the video series. I have missed an opportunity to keep them handy. But couple months later I have found a solution/hack which would have surely helped me back then.

This is a simple command line youtube download utility called youtube-dl. This is available via ppa and so installing it simple requires us to add the ppa and then install it.

$ sudo add-apt-repository ppa:nilarimogard/webupd8
$ sudo apt-get update
$ sudo apt-get install youtube-dl

youtube-dl is now available to use. Most basic usage is to pass it the url of the video that you want to download and let it do the rest.

$ youtube-dl <video_url>

Substitute the <video_url> with whatever you want to download.

But there is more to it. It allows you to download in various formats, audio only or video only downloads are also possibe.

To check the various formats available pass the -F flag.

$ youtube-dl -F <video_url>

This lists various formats for the video available. Format id is listed on the left of the output. To download using a specific format use the -f flag and pass the format id. youtube-dl will now download in specified format only. This is good since you might not want a FullHD quality and may flv will suffice just fine.

$ youtube-dl -f <id> <video_url>

Further more, it allows bulk/batch downloads via an external file which contains one url per line. youtube-dl will read each line from the file and download the video in the required format.

$ youtube-dl -f <id> file_with_youtube_links.txt

Once this is done, you will find a bunch of videos downloaded into the current directory.

For small quick videos, I found it convinient to use another tool like Avidemux to quickly crop mp4 files and then append them one of the other to generate a continuous video file which is more convinient. Opening small files in succession is definitely more tedious than watching a full length concatenated video. Maybe I am just being lazy or finding excuse for not using a playlist, but hey Avidemux does what it says and does it absolutely fine.

Its thus possible to organize youtube links in different files, download them using youtube-dl and concat then together using Avidemux to give a better 20-30 mins tutorial video rather than having dozens of smaller videos played out of order or having trouble of selecting the next video manually.

Useful hack for ethical download!