How to: Install Youtube-dl on Ubuntu [UPDATED]

Until it fell out of the Ubuntu software repositories and refused to work or update, I used the  Youtube-dl command-line tool all the time. Well, now it's back, here's how to install Youtube-dl on Ubuntu.

In case you're wondering, you can use this on other video hosting sites, not just Youtube; Dailymotion, Facebook, Google video, yahoo and many others. Usefully it has a resume feature which allows it to pick up partial downloads after interruptions without scrapping what it had to start over.

It is available on Windows, Linux, and Mac. You will need Python installed as it depends on python-based libraries

To install Youtube-dl

Owing to the lack of a Debian-based package in the software repositories, this is a command-line based tutorial.

Always begin with a system software update before installing new package. On Ubuntu this looks like:

$ sudo apt-get update –y
$ sudo apt-get upgrade –y

Reboot your system after updates to apply all changes.

The method to install youtube-dl described requires the curl package as a prerequisite. If you don't have it, install curl into your system using:

$ sudo apt-get install curl -y

You can then use curl to  download the youtube-dl into your system using:

$ curl -L -o /usr/bin/youtube-dl

You will need administrator permissions to install the binary to this folder, so you may need to prefix the command with sudo if it is not an admin account.

Next you will need to change the permissions for this downloaded binary file valid for executing as code:

$ sudo chmod 755 /usr/bin/youtube-dl

To list all available options with youtube-dl:

$ youtube-dl -h

Youtube-dl will download any formats that are available form the video site, but first you need to inventory all the formats available (MP4, 3GP, WebM, FLV, DASH audio and more).

The command structure is youtube-dl [options] [media URL]

For example

$ youtube-dl -F

Note capital 'F' in the command. This returns all the available formats for this video:

[youtube] z3DFT_qXrPc: Downloading webpage
[youtube] z3DFT_qXrPc: Downloading MPD manifest
[info] Available formats for z3DFT_qXrPc:
format code  extension  resolution note
139          m4a        audio only DASH audio   49k , m4a_dash container, mp4a.40.5 (22050Hz), 679.76KiB
140          m4a        audio only tiny  129k , m4a_dash container, mp4a.40.2@129k (44100Hz), 1.76MiB
251          webm       audio only tiny  134k , webm_dash container, opus @134k (48000Hz), 1.83MiB
278          webm       256x144    DASH video   95k , webm_dash container, vp9, 25fps, video only
160          mp4        256x144    DASH video  108k , mp4_dash container, avc1.4d400b, 25fps, video only
242          webm       426x240    DASH video  220k , webm_dash container, vp9, 25fps, video only
133          mp4        426x240    DASH video  242k , mp4_dash container, avc1.4d400c, 25fps, video only
134          mp4        640x360    360p  245k , mp4_dash container, avc1.4d401e@ 245k, 25fps, video only, 3.33MiB
243          webm       640x360    DASH video  405k , webm_dash container, vp9, 25fps, video only
244          webm       854x480    DASH video  752k , webm_dash container, vp9, 25fps, video only
135          mp4        854x480    DASH video 1155k , mp4_dash container, avc1.4d400b, 25fps, video only
136          mp4        1280x720   720p 1176k , mp4_dash container, avc1.64001f@1176k, 25fps, video only, 15.97MiB
247          webm       1280x720   DASH video 1505k , webm_dash container, vp9, 25fps, video only
18           mp4        640x360    360p  388k , avc1.42001E, 25fps, mp4a.40.2 (44100Hz), 5.28MiB
22           mp4        1280x720   720p 1305k , avc1.64001F, 25fps, mp4a.40.2 (44100Hz) (best)

You can then choose the format to download the video using the flag -f (lower case 'f') with the format number required:

$ youtube-dl -f 18

In this case, download the video in MP4 format at 640×360 resolution:

[youtube] z3DFT_qXrPc: Downloading webpage
[youtube] z3DFT_qXrPc: Downloading MPD manifest
[download] Destination: The Art of Foil Fencing Trailer-z3DFT_qXrPc.mp4
[download] 100% of 5.28MiB in 00:06

And we're back! RC