“Youtube-dl” Allows You to Download YouTube Videos Via The CLI on Linux Systems
Downloading videos from YouTube is something a lot of people do regardless of the type of platform that they are using, the truth is there are numerous third party GUI apps and in some cases browser extensions that handle the entire process. Linux offers a unique way of grabbing videos online via the terminal with the use of a simple command line.
The small but simple command in question is youtube-dl and it’s based on the highly acclaimed Python programming language. When executed, it can download videos from sites like YouTube, Google, DailyMotion, Yahoo, Photobucket, Metacafe, and many smaller sites.
It’s written using PyGTK and only requires the Python interpreter to function. The program is not a Linux exclusive and should run on any Unix, Mac OS X or Windows-based systems.
The youtube-dl download comes functions the same way as most download apps, but an added advantage where downloads can be saved even after being interrupted due to lost of internet connectivity or an unintentional kill.
Users can continue their downloads where they left off as long as the partially downloaded file is still in the original directory it started downloading in — You only have to use the URL of the download that was interrupted to relaunch it, the program will automatically continue where the download stopped.
Now let’s get into the thick of things. If you are using a system with Ubuntu Linux, you can install youtube-dl using this command:
sudo apt-get install youtube-dl
In the case where you are not using Ubuntu but on a different Linux-based distro, you can easily install youtube-dl with the following command:
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O/usr/local/bin/youtube-dl
To have the file execute properly after fetching it, you need to set the executable permission on the script. To do that, use the following command line:
sudo chmod a+rx /user/local/bin/youtube-dl
Now you are ready to download videos using youtube-dl. When you find a video you want to download on a website like Youtube, simply copy the URL and the run this command, in the place of “VIDEO_URL” paste the URL of the video you want to download.
With videos on YouTube offered in several formats, varying in size and resolution. You can look at the format of the videos by running youtube-dl with option “F” which will display all the formats that the video you want to download is offered in.
Run this command:
youtube-dl -F http://www.youtube.com/watch?v=BlXaGWbFVKY
The results will be something like this:
BlXaGWbFVKY: Downloading video webpage
BlXaGWbFVKY: Downloading video info webpage
BlXaGWbFVKY: Extracting video information
- 37 : mp4 [1080×1920]
- 46 : webm [1080×1920]
- 22 : mp4 [720×1280]
- 45 : webm [720×1280]
- 35 : flv [480×854]
- 44 : webm [480×854]
- 34 : flv [360×640]
- 18 : mp4 [360×640]
- 43 : webm [360×640]
- 5 : flv [240×400]
- 17 : mp4 [144×176]
From the list, you can select the video you want to download in the format of your taste.
A simple example is when you want to download the mp4 (1080×1920) version, use this command:
youtube-dl -f 37 http://www.youtube.com/watch?v=BlXaGWbFVKY
You can also check to see if the videos come with codecs subs and you can adjust them by using this command:
youtube-dl –all-subs –skip-download https://www.youtube.com/watch?v=Ye8mB6VsUHw
If you come across a playlist that you love and want to have a copy on your Linux-based computer, you can download it using this command with the “playlist_url” is where you paste the URL of the playlist you want to get.
youtube-dl -cit playlist_url
This is the end of this tutorial, be sure to leave us your thoughts in the comments and stay tuned to UBN!