How-to: Youtube-dl video download basics


Often times various browser-based video downloaders, even the good ones, fail to penetrate YouTube's byzantine front-end to access all the formats available.

This is where the terminal-based Youtube-dl is able to query the server directly to get exactly what you want. And, for a terminal based tool, it is simplicity itself.


Installation
Youtube-dl is available straight from Ubuntu Software Centre (or whichever is your favourite package manager, or you can use a apt-get command from the terminal, such as:

sudo apt install youtube-dl

or use a wget command, like I did:

sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl

It's worth issuing an update command to ensure you have the latest version, and periodically thereafter:

sudo youtube-dl -U

Dependencies
FFmpeg is also required to download 720p videos from YouTube and convert videos to other formats. If you're serious about media file manipulation, you'll have this anyway, right?

Usage
Given my central issue of saving instructional videos and the occasional soundtrack, I've only used two commands from this application so far.

1. From the Youtube page you're trying to download media from, go to the address bar and copy the URL to the clipboard.

2. Open a terminal and query for the formats available using the basic youtube-dl -F command pasting the Youtube URL as a parameter, as in:

youtube-dl -F https://www.youtube.com/watch?v=DdIdZwDqkmg


NOTE: the -F is UPPER case! Yes, it matters, this is Linux after all.

This should return the full list of available formats for this specific video:

[youtube] DdIdZwDqkmg: Downloading webpage
[info] Available formats for DdIdZwDqkmg:
format code  extension  resolution note
249          webm       audio only tiny   82k , opus @ 50k (48000Hz), 3.24MiB
250          webm       audio only tiny  107k , opus @ 70k (48000Hz), 4.32MiB
140          m4a        audio only tiny  130k , m4a_dash container, mp4a.40.2@128k (44100Hz), 7.83MiB
251          webm       audio only tiny  208k , opus @160k (48000Hz), 8.57MiB
394          mp4        256x144    144p   94k , av01.0.00M.08, 30fps, video only, 4.13MiB
278          webm       256x144    144p   98k , webm container, vp9, 30fps, video only, 4.79MiB
160          mp4        256x144    144p  111k , avc1.4d400c, 30fps, video only, 4.07MiB
395          mp4        426x240    240p  197k , av01.0.00M.08, 30fps, video only, 7.10MiB
242          webm       426x240    240p  224k , vp9, 30fps, video only, 8.58MiB
133          mp4        426x240    240p  246k , avc1.4d4015, 30fps, video only, 7.14MiB
396          mp4        640x360    360p  352k , av01.0.01M.08, 30fps, video only, 11.93MiB
243          webm       640x360    360p  409k , vp9, 30fps, video only, 15.15MiB
134          mp4        640x360    360p  634k , avc1.4d401e, 30fps, video only, 15.66MiB
18           mp4        640x360    360p  493k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 29.84MiB (best)


The first column of numbers lists the identifiers for each format.

NOTE that not all videos have the same file formats and qualities available, so the list above is neither a standard nor exhaustive. It will depend on the source file that was uploaded and what Youtube's servers were able to convert at verious qualities and formats. Hi-res video will have a stack of extra options.

The first column of numbers identify each available format.

3. Choose the format you want and issue the command:

youtube-dl -f 140 https://www.youtube.com/watch?v=DdIdZwDqkmg

NOTE: the -f parameter is LOWER case.

The numeric string 140 is the file format from our list, in this case the m4a, audio-only version.

The URL is the same, specifying this particular file.

When you hit enter, you'll get a response similar to this:

[youtube] DdIdZwDqkmg: Downloading webpage
[youtube] DdIdZwDqkmg: Downloading js player vfl_CsZz6
[youtube] DdIdZwDqkmg: Downloading js player vfl_CsZz6
[download] Destination: Daft Punk - The Grid (pierrotechnique Remix)-DdIdZwDqkmg.m4a
[download] 100% of 7.83MiB in 00:05
[ffmpeg] Correcting container in "Daft Punk - The Grid (pierrotechnique Remix)-DdIdZwDqkmg.m4a"


That's it.

You can do a lot more with Youtube-dl from the command line, and I intend to delve into it's advanced operations in the future. RC

Side note: when you open your terminal you may want to change directory to the location where you want to store your downloaded files, otherwise it will use your terminal default.

Second side note: the usual statement about saving media for personal use and not violating the rights of the original copyright holders applies.

Comments