31 October 2014

youtube-dl (Command Based Youtube Downloader)

Downloading youtube.com videos to local machine is always a challenge as the streaming sites keep on updating their policies in blocking the videos.
But there is a tool that is available in the command line (Terminal based) on Linux Operating Systems.
That is youtube-dl, this is a python based code and can be executed in linux OS without any hassles.

youtube-dl in windows or Mac OS can be achieved by installing python interpreter and try it.

for installing in linux, the command is
$prompt] sudo yum install youtube-dl (in redhat or centos or fedora)
$prompt] sudo apt-get install youtube-dl (ubuntu or linux mint)
See the image for downloading in Fedora 20
fedora20
Youtube-dl in Fedora 20

In ubuntu, you can update the sudo package before installing the youtube-dl.
sudo apt-get update

To download videos 
$prompt] youtube-dl http://www.youtube.com/watch?v=D980jXvyKUY

the above command will download the video in the best possible format. See the image below.
The video downloaded is of the format webm (Its a Web Movie format from Google for optimized view in web browsers)
youtube
Youtube-dl
To view all formats, use the following command,
$prompt] youtube-dl -F http://www.youtube.com/watch?v=D980jXvyKUY
[youtube] Setting language
[youtube] D980jXvyKUY: Downloading webpage
[youtube] D980jXvyKUY: Downloading video info webpage
[youtube] D980jXvyKUY: Extracting video information
[info] Available formats for D980jXvyKUY:
format code extension resolution  note
139         m4a       audio only  DASH audio , audio@ 48k (worst)
140         m4a       audio only  DASH audio , audio@128k
160         mp4       192p        DASH video
133         mp4       240p        DASH video
17          3gp       176x144  
36          3gp       320x240  
5           flv       400x240  
18          mp4       640x360     

43          webm      640x360     (best)

The above is output and to download the corresponding video format, then here is the command
$prompt] youtube-dl -f 18 http://www.youtube.com/watch?v=D980jXvyKUY
The above command will download the file in the mp4 format as specified in the option obtained in the previous command.

if you need any help on the commands, you can use the following command 
$prompt] youtube-dl --help

Often, youtube-dl is updated, it can be easily updated as given below,
$prompt] sudo youtube-dl -U

Also now youtube-dl supports various other video streaming sites also, to name a few, vimeo.com, dailymotion.com, etc.

If you are behind the proxy, type the command in the terminal  
export http_proxy=172.16.1.1:8080/ 
or copy the above line in /etc/profile.d/proxy.sh (this will be set for all the users of the computer, also need root password)

Download and Enjoy!!!

 T S Pradeep Kumar