5 youtube-dl tips you might not know about

Published in: Linux, Quick Tips

youtube-dl is a python based command line video downloader that just works. Despite its name would suggest, youtube-dl downloads more than just youtube videos, it currently supports more than 800 online video and audio sites. If you are using a desktop app or web app to download videos now, chances are it’s using youtube-dl in the back-end. You are better off using youtube-dl instead considering you get so much more power and options with it. Here are some simple tips to get you started.

Install from the source

There are multiple options to get started with installing youtube-dl, I personally recommend installing from the source simply because how frequently its database gets updated and most OS package managers are a bit late when keeping up with the updates. The best thing about youtube-dl is that it runs on all major OS as long as you have python installed.

Windows users can download latest exe file. For Linux, MacOS users:

sudo curl -L https://yt-dl.org/latest/youtube-dl -o /usr/local/bin/youtube-dl (1)
sudo chmod a+rx /usr/local/bin/youtube-dl (2)
1 Download using cURL to the proper application directory.
2 Apply proper access permission to run youtube-dl.

Always update to the latest version

Online video players are updated frequently which can often break how youtube-dl download video files from your favorite site. So, just like browser video downloading extensions, it’s a good idea to keep it up-to-date. You could make a cronjob, but I prefer to do it manually.

Updating youtube-dl is as simple as typing youtube-dl -U:


Download specific video quality

Downloading with youtube-dl is as simple as typing youtube-dl video_url and this is how most people limit their usage, but you can also pick and choose the quality of the video. Most online video players, like youtube, stores multiple quality of video files for viewers convenience. You can list all the video files available for you to download by using this command: youtube-dl --list-formats video_url

youtube-dl --list-formats https://www.youtube.com/watch?v=9D05ej8u-gU
 9D05ej8u-gU: Downloading webpage
 9D05ej8u-gU: Downloading video info webpage
 9D05ej8u-gU: Extracting video information
 9D05ej8u-gU: Downloading MPD manifest
[info] Available formats for 9D05ej8u-gU:
format code  extension  resolution note
249          webm       audio only DASH audio   51k , opus @ 50k (48000Hz), 1.21MiB
250          webm       audio only DASH audio   68k , opus @ 70k (48000Hz), 1.50MiB
171          webm       audio only DASH audio  120k , vorbis@128k (44100Hz), 2.59MiB
140          m4a        audio only DASH audio  129k , mp4a.40.2@128k (44100Hz), 3.27MiB
251          webm       audio only DASH audio  131k , opus @160k (48000Hz), 2.93MiB
160          mp4        256x144    DASH video  119k , avc1.4d400c, 13fps, video only, 2.73MiB
278          webm       256x144    DASH video  131k , vp9, 13fps, video only, 2.19MiB
133          mp4        426x240    DASH video  252k , avc1.4d4015, 25fps, video only, 6.12MiB
242          webm       426x240    DASH video  271k , vp9, 25fps, video only, 2.93MiB
243          webm       640x360    DASH video  503k , vp9, 25fps, video only, 5.71MiB
134          mp4        640x360    DASH video  602k , avc1.4d401e, 25fps, video only, 6.66MiB
244          webm       854x480    DASH video  902k , vp9, 25fps, video only, 10.15MiB
135          mp4        854x480    DASH video 1104k , avc1.4d401e, 25fps, video only, 13.70MiB
247          webm       1280x720   DASH video 1797k , vp9, 25fps, video only, 21.76MiB
136          mp4        1280x720   DASH video 2206k , avc1.4d401f, 25fps, video only, 29.43MiB
212          mp4        854x480    DASH video 1957k , avc1.4d401e, 1fps, video only, 31.92MiB
17           3gp        176x144    small , mp4v.20.3,  mp4a.40.2@ 24k
36           3gp        320x180    small , mp4v.20.3,  mp4a.40.2
43           webm       640x360    medium , vp8.0,  vorbis@128k
18           mp4        640x360    medium , avc1.42001E,  mp4a.40.2@ 96k
22           mp4        1280x720   hd720 , avc1.64001F,  mp4a.40.2@192k (best)

You can choose which format to download by using the format code listed like this:

youtube-dl -f 22 https://www.youtube.com/watch?v=9D05ej8u-gU
 9D05ej8u-gU: Downloading webpage
 9D05ej8u-gU: Downloading video info webpage
 9D05ej8u-gU: Extracting video information
 9D05ej8u-gU: Downloading MPD manifest
[download] Destination: The Most Astounding Fact - Neil deGrasse Tyson-9D05ej8u-gU.mp4
[download] 100% of 41.17MiB in 01:10

Download only the mp3 audio track from youtube video

Sometimes you don’t really care about downloading the whole video, you only want the audio and it can be easily done using youtube-dl without having to download the video first and then extract the audio from it. As seen from the output of previous --list-format command youtube stores audio and video formats separately, so youtube-dl just downloads the audio file, usually in m4a or webm format and then converts it into mp3. Using this command: youtube-dl --extract-audio --audio-format mp3 video-url. You will need ffmpeg or avconv for this to work since the audio needs to be converted to your preferred mp3 format.

youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch?v=9D05ej8u-gU
 9D05ej8u-gU: Downloading webpage
 9D05ej8u-gU: Downloading video info webpage
 9D05ej8u-gU: Extracting video information
 9D05ej8u-gU: Downloading MPD manifest
[download] Destination: The Most Astounding Fact - Neil deGrasse Tyson-9D05ej8u-gU.webm
[download] 100% of 2.93MiB in 00:02
[ffmpeg] Destination: The Most Astounding Fact - Neil deGrasse Tyson-9D05ej8u-gU.mp3
Deleting original file The Most Astounding Fact - Neil deGrasse Tyson-9D05ej8u-gU.webm (pass -k to keep)

If you don’t care about converting audio to mp3 format and want to keep the original format. You can download the specific audio format using the format code shown before.

Downloading multiple videos from a list

You can create a text list with youtube video links (or any of the other 800+ supported sites), one line at a time using youtube-dl to download a lot of videos without having to do it manually. Like this: youtube-dl -a video_links.txt.

about | pages | archive | rss