Download videos from youtube, metacafe, dailymotion etc. easily using this python script - Youtube-dl

I think there is a time in every Internet user's life when he/she is crazy about Youtube, provided the bandwidth is not an issue . I went through the same phase in the 2nd year of my graduation. I kept searching and downloading youtube for more bball videos - jordan, kobe, iversion, freestyle etc. I didn't know then how to download videos and usually wasted a lot of my time, copying and renaming the videos from the cached buffer of firefox. I still remember, I had a freshly installed ubuntu hardy and I searched for youtube in synaptic and found this great python script to download youtube videos, youtube-dl.

Although there are a lot of web based tools available these days, my favourite being the firefox addon videodownloadhelper, but nothing can beat the way we can make use of youtube-dl in scripts and automate the whole thing, or one could say, a linuxer's way of doing things .

Not just youtube, it works for various popular video sharing websites, including Metacafe, video.google.com, dailymotion and photobucket.

Install Youtube-dl

I am not sure if this script is available on Fedora/Redhat systems or not, but its just a small python program which can be downloaded and run directly. No, need to install. Download the recent version from project's download page, unzip it and run the executable directly.

[shredder12]$ tar -xvjf youtube-dl.tar.bz2; cd youtube-dl

The executable in the folder is the script you need.

Ubuntu/Debian users can easily install it by running the following command in the terminal.

[shredder12]$ sudo apt-get install youtube-dl

or, use the software center if you prefer it.

For readers, who don't realise the capability of this tool just take a look at the features this small script provides and I bet you won't be under-estimating it then.

The simplest syntax you can wish from a video downloading script

[shredder12]$ youtube-dl <youtube-url>

Use various output formats for the downloaded filename

The above method will name the downloaded video as <video-id>.flv. If you want to assign the video its title then use the -t option.

[shredder12]$ youtube-dl -t youtube_url

This url is usually a little modified eg. the inclusion of underscore('_') etc. Using the -l option, you can ask youtube-dl to use the literal term.

Another way is to specify the output format (-o). A simple example would be to use a static/fixed filename.

[shredder1]$ youtube -o horror.flv youtube_url

But using special characters, you can even mention the type of format you want for your filename, e.g. The default output format is the video-id. Even after using the -t or -l option, the format is (title)-(video_id).(format). So, if you want a more descriptive title say, (title)-(uploder).(format). Then you should mention something like.

[shredder12]$ youtube-dl -o "%(title)s-%(uploader)s.%(ext)s" youtube_url

Set the format of the downloaded video

Regular youtube would be aware of the format or fmt convention. They identify the quality of the codec of the video. e.g. fmt 17 signifies 3gp quality etc. For more information on the fmt option, check out this page.

[shredder12]$ youtube-dl -f 35 -l youtube_url

If you are interested in downloading only the best quality, then don't use this. The default action of youtube-dl is to go for the best quality video.

There is even a direct option for downloading a mobile version, the -m option. This is similar to using -f 17.

If you want all the available formats, then you don't have to do it manually. Just go for the --all-formats option.

Download multiple videos using youtube-dl, aka batch-mode

This feature is a charm of youtube-dl. Just create a file consisting of URLs of all the video you wish to download and pass it as a parameter to youtube-dl using -a option.

[shredder12]$ youtube-dl -t -a urls_file.txt

Other options

  • Limiting the rate of downloading, --limit-rate=40k or -r 40k, i.e. 40 kbs.
  • Set the username and password to download mature content.
  • Number of retries using the --retries=6 or -R 6.
  • You can even simulate the downloading using -s options.
  • There are other options that let you download only the title(--get-title or -e), description(--get-description) or thumbnail(--get-thumbnail) of the video to be downloaded.
  • You can easily continue a previously downloaded partial file using the -c or --continue option.

Finally, I am not sure if anyone has said this before but I think youtube-dl is the wget for video downloading

1 Comment

drmike (not verified)
November 11th, 2010 01:38 am
Looks like they moved: http://rg3.github.com/youtube-dl/

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.