How to download YouTube videos right from the terminal on Ubuntu

How to download YouTube videos right from the terminal on Ubuntu

How to download YouTube videos right from the terminal on Ubuntu

Downloading YouTube videos has been one of the most common user activities since the rise of the world’s most popular entertainment content website. The reason to download something from YouTube can be to have access to it without having to be online, keep something that may get restricted in your geographic location in the future, or download music videos just to burn them on an audio CD. In this quick guide, we will take a look on how to download YouTube videos right from the terminal.if(typeof __ez_fad_position != ‘undefined’){__ez_fad_position(‘div-gpt-ad-howtoforge_com-box-3-0’)};

Our first step will be to download the video. While there are many ways to do this, we will use a tool that can work through our terminal for greater simplicity and power. The tool is called “youtube-dl” and Ubuntu users may install it by opening a terminal and typing “sudo apt-get youtube-dl”. Just make sure that you have “ffmpeg” also installed and that your libav version is newer than v10. This is not absolutely required for youtube-dl to work, but if your libav version is too old you will get limited functionality. To solve this in Ubuntu, run the following commands in a terminal as root:if(typeof __ez_fad_position != ‘undefined’){__ez_fad_position(‘div-gpt-ad-howtoforge_com-medrectangle-3-0’)};

sudo add-apt-repository ppa:heyarje/libav-11
sudo apt-get update
sudo apt-get install libav-tools

After this is done, you may simply download any youtube video by opening a terminal and typing “youtube-dl ” as shown in the following screenshot:

Download videa from YouTube

This will download the video on default settings which is your Home folder as the location, max resolution as the selected quality, and mkv as the video format.

Format options

Now, let’s take a look on how to set all this starting with the format options. First, we need to determine what the available formats for our target video are. To do this, use the “youtube-dl -F ” command.

Available Video Formats

Now to choose a format from the list, you may simply use the corresponding code, or the filetype name preceded by the “-f” parameter in the command. For example, if I want to download the “audio only” type in the Opus format, I will use “youtube-dl -f 250 .

Download audio onlyif(typeof __ez_fad_position != ‘undefined’){__ez_fad_position(‘div-gpt-ad-howtoforge_com-medrectangle-4-0’)};

If you want to download the video in all available formats, you may use the “–all-formats” parameters instead of downloading them one by one. In the case of playlists, you should know that those are reflected in the video url, so youtube-dl will download all videos contained in a playlist unless told otherwise (this works for version 2014.02.17 and above) This “telling” can be done by using the “–playlist-items” parameter followed by a space and the items numbers separated by commas. This will only download the specified items from the playlist. If the playlist items are continuous, you may also specify the range using numbers and dashes like 3-6 instead of 3,4,5,6.

Now that we’re at it, in most cases of downloading playlists, we do it for the audio. You may skip the post-processing work of having to turn the videos into mp3s by adding the following two parameters in the command: “–extract-audio” and “
–audio format mp3”. This will download the specified video or playlist directly into an mp3 format.

Download as mp3 file

Another nice feature in regards to the playlist downloading is the ability to tell youtube-dl to download only the most popular videos out of a large playlist that has too many items for you to check one by one. This is done by using the “–min-views [number]” parameter.

Finally, youtube-dl can also download subtitles with your video, a feature that is very useful in many situations. We can check what languages are available by typing “youtube-dl –list-subs ”. This will also display the subs that are automatically generated by YouTube’s “audio to text” algorithms.

Download subtitles

To choose the subtitle that you need, use the “–sub-lang [language code] ”. For example, if I wanted to download the particular video with English subs, I would use the command as “youtube-dl –sub-lang en ”.

I believe the above commands to be adequate to cover the most common user needs, but it is important to note that youtube-dl has a much wider spectrum of functionality and operational capacity. If you want to discover this, use the “–help” parameter and start exploring further.

YouTube continuously filters out content that violates copyrights and it is often the case that you may have limited-time access to something that is otherwise “not free” in your country. HowToForge and the editor of this post don’t encourage the downloading of copyrighted material, nor take the responsibility for such actions. This guide is provided with the note that its readers are responsible for checking the copyrights of the material and their application in their country before downloading it.

About the Author

Leave a Reply