What is youtube-dl?
youtube-dl is a Python-based command-line tool that allows downloading videos from YouTube, Dailymotion, Photobucket, Facebook, Yahoo, Metacafe, Depositfiles and a few more similar sites. It is written in pygtk and requires Python interpreter to run this program, it’s not platform restricted. It should run on any Unix, Windows or in Mac OS X based systems.
The youtube-dl tool supports resuming interrupted downloads. If youtube-dl is killed (for example, by Ctrl-C or due to loss of Internet connectivity) in the middle of the download, you can simply re-run it with the same YouTube video URL. It will automatically resume the unfinished download as long as a partial download is present in the current directory. Which means you don’t need download managers in Linux just for resuming downloads.
youtube-dl features
This tiny tool offers so many features that it won’t be an exaggeration to call it the best YouTube downloader for Linux.
- Download videos from not only YouTube but other popular video websites like Dailymotion, Facebook etc
- Allows downloading videos in several available video formats, such as MP4, WebM etc.
- You can also choose the quality of the video being downloaded. If the video is available in 4K, you can download it in 4K, 1080p, 720p, etc.
- Automatic pause and resume of video downloads.
- Allows to bypass YouTube geo-restrictions.
How to install youtube-dl on Linux
youtube-dl is a popular program and, is available in the default repositories of most Linux distributions, if not all. But unfortunately, you cannot use these standard packages in your distribution. They are old and most probably don’t work. You can get a working youtube-dl either from the official GitHub repository, or from the youtube-dl nightly release.
Install youtube-dl Nightly
youtube-dl offers a nightly release, which contains recent changes and fixes so that you can run it without any error. I will describe the easiest way to set it up. First go to the Nightly release GitHub page.
Here, you can get a python file, named youtube-dl
. Just download it. Once downloaded, copy that file to /usr/local/bin/
. For this, open a terminal where you downloaded the file and then run:
sudo cp youtube-dl /usr/local/bin/
Now, give the file the required permissions using the chmod command.
sudo chmod a+rx /usr/local/bin/youtube-dl
You cannot just run youtube-dl
now, because of issue with python naming. It uses python
while in Ubuntu-based systems, it is python3
. So, you can create an alias for youtube-dl in your .bashrc
.
alias youtube-dl='python3 /usr/local/bin/youtube-dl'
That’s it. You have set up youtube-dl in your system.
Alternatively, compile from Git Master
If you are running an Ubuntu-based Linux distribution, you can install the tools needed to compile youtube-dl using the command below:
sudo apt install build-essential git
Now, clone the git repository and make the youtube-dl:
git clone https://github.com/ytdl-org/youtube-dl.git
cd youtube-dl/
make youtube-dl
Once you made youtube-dl, you need to copy it to a location in the path. Use the command below:
sudo cp youtube-dl /usr/local/bin/
As in the previous case, if you run youtube-dl from the command line, you will get an error about python because it tries to run using python
while in Ubuntu, it is python3
. You can create an alias on your .bashrc
like:
alias youtube-dl='python3 /usr/local/bin/youtube-dl'
You can now use youtube-dl command.
Important: Keep your youtube-dl updated
Once installed, you can update it to the latest version using this command. This is helpful when you have been using it for a few months:
youtube-dl -U
Using YouTube-dl for downloading videos
To download a video file, simply run the following command. Where, “VIDEO_URL” is the URL of the video that you want to download.
youtube-dl <video_url>
The video is saved in the directory from where you run the command.
Download YouTube videos in various formats and quality size
These days, YouTube videos have different resolutions, you first need to check available video formats of a given YouTube video. For that run, youtube-dl with -F
option. It will show you a list of available formats.
youtube-dl -F <video_url>
Its output will be like:
Now among the available video formats, choose one that you like. For example, if you want to download it in MP4 version and 1080 pixel, you should use:
youtube-dl -f 137 <video_url>
Download subtitles of videos using youtube-dl
First, check if there are subtitles available for the video. To list all subs for a video, use the command below:
youtube-dl --list-subs <video_url>
To download all subs, but not the video:
youtube-dl --all-subs --skip-download <video_url>
Download entire YouTube playlist
To download a playlist, simply run the following command. Where, “playlist_url” is the URL of the playlist that you want to download.
youtube-dl -cit <playlist_url>
Download only audio from YouTube videos
You need ffmpeg
installed on your system to download audio from videos. If not already installed, open a terminal and run:
sudo apt install ffmpeg
If you just want to download the audio from a YouTube video, you can use the -x option to simply extract the audio file from the video.
youtube-dl -x <video_url>
The file format is M4A/Ogg, which you may not like. You can specify the file format of the audio file in the following manner:
youtube-dl -x --audio-format mp3 <video_url>
And a lot more can be done with youtube-dl
youtube-dl is a versatile command line tool and provides a number of functionalities. No wonder it is such a popular command line tool.