Download videos from YouTube with youtube-dl

  • 17 February 2021
Image not Found

youtube-dl is a cli-tool that allows us download videos from various sources (not only from YouTube) from the terminal interface. I wrote this tutorial using the version 2020.06.16.1, if you want to know what version you are running use --version:

$ youtube-dl --version
2020.06.16.1

Before starting to download a video you must make sure in what format, quality and weight you want, with the command youtube-dl --list-formats followed by the video URL:

$ youtube-dl --list-formats https://www.youtube.com/watch?v=SwpkPf63304
249          webm       audio only tiny   66k , opus @ 50k (48000Hz), 31.06MiB
250          webm       audio only tiny   89k , opus @ 70k (48000Hz), 41.10MiB
140          m4a        audio only tiny  135k , m4a_dash container, mp4a.40.2@128k (44100Hz), 83.58MiB
251          webm       audio only tiny  179k , opus @160k (48000Hz), 83.12MiB
394          mp4        256x144    144p   99k , av01.0.00M.08, 25fps, video only, 50.33MiB
278          webm       256x144    144p  127k , webm container, vp9, 25fps, video only, 58.19MiB
160          mp4        256x144    144p  155k , avc1.4d400c, 25fps, video only, 63.09MiB
242          webm       426x240    240p  226k , vp9, 25fps, video only, 127.02MiB
395          mp4        426x240    240p  237k , av01.0.00M.08, 25fps, video only, 111.59MiB
243          webm       640x360    360p  432k , vp9, 25fps, video only, 230.93MiB
133          mp4        426x240    240p  456k , avc1.4d4015, 25fps, video only, 147.51MiB
396          mp4        640x360    360p  483k , av01.0.01M.08, 25fps, video only, 206.01MiB
244          webm       854x480    480p  771k , vp9, 25fps, video only, 391.84MiB
397          mp4        854x480    480p  821k , av01.0.04M.08, 25fps, video only, 365.63MiB
134          mp4        640x360    360p  995k , avc1.4d401e, 25fps, video only, 288.22MiB
398          mp4        1280x720   720p 1529k , av01.0.05M.08, 25fps, video only, 730.90MiB
247          webm       1280x720   720p 1539k , vp9, 25fps, video only, 733.20MiB
135          mp4        854x480    480p 1638k , avc1.4d401e, 25fps, video only, 423.79MiB
399          mp4        1920x1080  1080p 2658k , av01.0.08M.08, 25fps, video only, 1.26GiB
248          webm       1920x1080  1080p 2693k , vp9, 25fps, video only, 1.53GiB
136          mp4        1280x720   720p 3117k , avc1.4d401f, 25fps, video only, 734.95MiB
137          mp4        1920x1080  1080p 5577k , avc1.640028, 25fps, video only, 2.37GiB
18           mp4        640x360    360p  724k , avc1.42001E, 25fps, mp4a.40.2@ 96k (44100Hz), 467.68MiB (best)

In the first column a reference number appears, that will be our option to choose, for example 18 which is the last one on that list:

$ youtube-dl -f 18 https://www.youtube.com/watch?v=SwpkPf63304

Get only audio (mp3)

$ youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=SwpkPf63304

References

https://www.tecmint.com/download-mp3-song-from-youtube-videos/

https://blog.desdelinux.net/youtube-dl-tips-que-no-sabias/

http://www.webupd8.org/2014/02/video-downloader-youtube-dl-gets.html

You May Also Like

How to use GoPlantUML?

How to use GoPlantUML?

goplantuml generates code in PlantUML format that represents a diagram of the relationships between the Go receiver structs, they are analogous to …

Record video screen with FFmpeg

Record video screen with FFmpeg

ffmpeg is a cli-tool that in addition to allowing multimedia file format conversion you can also record screen video starting from the terminal …