youtube-dl is a small and powerful command-line program for downloading videos from YouTube and other sites such as Facebook, Yahoo, Google Video.
It supports almost 1150+ websites.
This requires the Python interpreter to work. So, make sure you already have Python installed on your system.
It is not platform independent and it should work on any Unix/Linux, Windows and Mac OS X based systems.
How to Install YouTube-DL on Linux
You can easily install YouTube-DL on Linux by downloading the YouTube-DL binary from the developer website using the curl command or the wget command.
This method works on all major Linux distributions such as Debian, RHEL, Ubuntu, LinuxMint, CentOS, Fedora, suse, openSUSE, ArchLinux, Manjaro, Mageia, etc,.
In this method you always get the latest version of Youtube-dl.
Download and install the youtube-dl binary using the cURL command.
$ sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl $ sudo chmod a+rx /usr/local/bin/youtube-dl
Download and install the youtube-dl binary using the wget command.
$ sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl $ sudo chmod a+rx /usr/local/bin/youtube-dl
Alternatively you can install YouTube-dl using the pip Package Manager.
$ sudo pip install youtube-dl
Run the following command to update YouTube-dl to the latest version.
$ sudo youtube-dl -U or $ sudo -H pip install --upgrade youtube-dl
How to Use YouTube-DL to Download Videos
Use the following format to download any video from supported sites. It’s straight forward, just enter the video URL you want to download.
The following is a general syntax for YouTube-DL.
# youtube-dl [Options] [Video URL]
How to Download a Video from YouTube
Simple type youtube-dl in the terminal followed by the video URL to download a single video. For example.
# youtube-dl https://www.youtube.com/watch?v=SjiwQxbol7I [youtube] SjiwQxbol7I: Downloading webpage [youtube] SjiwQxbol7I: Extracting video information [download] Destination: Linux _ Unix - Find Out DNS IP Addresss Settings Tutorial-SjiwQxbol7I.f136.mp4 [download] 100% of 16.10MiB in 00:13 [download] Destination: Linux _ Unix - Find Out DNS IP Addresss Settings Tutorial-SjiwQxbol7I.f140.m4a [download] 100% of 2.55MiB in 00:02 [ffmpeg] Merging formats into "Linux _ Unix - Find Out DNS IP Addresss Settings Tutorial-SjiwQxbol7I.mp4" Deleting original file Linux _ Unix - Find Out DNS IP Addresss Settings Tutorial-SjiwQxbol7I.f136.mp4 (pass -k to keep) Deleting original file Linux _ Unix - Find Out DNS IP Addresss Settings Tutorial-SjiwQxbol7I.f140.m4a (pass -k to keep)
To download a playlist, input the playlist URL.
# youtube-dl https://www.youtube.com/channel/UCnKhQkCUS1oCEvjuTfU4xIw/playlists
To download the entire channel, add the URL of the corresponding channel.
# youtube-dl https://www.youtube.com/channel/UCnKhQkCUS1oCEvjuTfU4xIw
How to Download Multiple Videos at Once from YouTube
If you want to download multiple videos at once, add URLs with space as follows.
# youtube-dl [URL1] [URL2]
Additionally, videos can be downloaded in bulk using a text file. Make sure there is only one URL in each line
# youtube-dl -a videos-list.txt
How to Download Video with Custom Name
If you want to download a video with a custom name of your choice, use the following format.
# youtube-dl -o linux-video https://www.youtube.com/watch?v=SjiwQxbol7I [youtube] SjiwQxbol7I: Downloading webpage [youtube] SjiwQxbol7I: Extracting video information [download] Destination: linux-video.f136.mp4 [download] 100% of 16.10MiB in 00:13 [download] Destination: linux-video.mp4.f140 [download] 100% of 2.55MiB in 00:02 [ffmpeg] Merging formats into "linux-video.mp4" Deleting original file linux-video.f136.mp4 (pass -k to keep) Deleting original file linux-video.mp4.f140 (pass -k to keep)
If you want to save a video with your preferred name elsewhere, the command is as follows.
# youtube-dl -o ~/Videos/linux-video https://www.youtube.com/watch?v=SjiwQxbol7I
How to Download a Specific Video from the Playlist
Youtube-dl allows you to download a specific video or range of videos or multiple videos from a playlist of 100 songs.
# youtube-dl --playlist-items 5 https://www.youtube.com/channel/UCnKhQkCUS1oCEvjuTfU4xIw/playlists # youtube-dl "--playlist-items 3,7,8,15" https://www.youtube.com/channel/UCnKhQkCUS1oCEvjuTfU4xIw/playlists # youtube-dl "--playlist-items 10-17" https://www.youtube.com/channel/UCnKhQkCUS1oCEvjuTfU4xIw/playlists
How to Check Available Video Format and their Size
Add the “-F” option with the youtuble-dl command if you want to verify the video formats, resolution and their size available for a particular YouTube video.
# youtube-dl -F https://www.youtube.com/watch?v=SjiwQxbol7I [youtube] SjiwQxbol7I: Downloading webpage [youtube] SjiwQxbol7I: Extracting video information [info] Available formats for SjiwQxbol7I: format code extension resolution note 171 webm audio only DASH audio , audio@128k 140 m4a audio only DASH audio , m4a_dash container, aac @128k 278 webm 144p DASH video , webm container, VP9, video only 160 mp4 144p DASH video , video only 242 webm 240p DASH video , video only 133 mp4 240p DASH video , video only 243 webm 360p DASH video , video only 134 mp4 360p DASH video , video only 244 webm 480p DASH video , video only 135 mp4 480p DASH video , video only 247 webm 720p DASH video , video only 136 mp4 720p DASH video , video only 17 3gp 176x144 36 3gp 320x240 5 flv 400x240 43 webm 640x360 18 mp4 640x360 22 mp4 1280x720 (best)
How to Download Video in Other Format
Select which format and resolution you want from the output above. This output will be different for each video.
Once you’ve decided, add the video format code with the “-f” option to download. For instance, we’re going to download a video in “3gp” format.
# youtube-dl -f 17 https://www.youtube.com/watch?v=SjiwQxbol7I [youtube] SjiwQxbol7I: Downloading webpage [youtube] SjiwQxbol7I: Extracting video information [download] Destination: Linux _ Unix - Find Out DNS IP Addresss Settings Tutorial-SjiwQxbol7I.3gp [download] 100% of 1.14MiB in 00:00
How to Use a Special String to Download the Video in a Different Format
By default youtube-dl tries to download the best quality available. If you want to download a different video format due to slow or intermittent connection, use the format below.
- best: Select the best quality format for video and audio for a given file.
- worst: Select the worst quality format for video and audio for a given file.
# youtube-dl -f worst https://www.youtube.com/watch?v=SjiwQxbol7I
How to Download only Audio from a Video
If you want to download only audio from a YouTube video, add the “-x” option and “audio format” with the YouTube-dl command to download it.
By default, if you don’t specify the audio format, it downloads the audio with the Ogg format.
# youtube-dl -x https://www.youtube.com/watch?v=SjiwQxbol7I
If you want to download audio with a specific format. For instance mp3.
# youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=SjiwQxbol7I
How to Download Youtube Videos with Subtitles
To download a YouTube video with automatically generated subtitle files, use the following option with the youtube-dl command.
# youtube-dl --write-auto-sub https://www.youtube.com/watch?v=SjiwQxbol7I
To List all available subtitles for the video.
# youtube-dl --list-subs https://www.youtube.com/watch?v=SjiwQxbol7I
To download a video with specific language sub-titles, use the following options.
# youtube-dl --sub-lang en https://www.youtube.com/watch?v=SjiwQxbol7I
How to Check more Options from the YouTube-DL Manual
youtube-dl is a versatile command line tool and provides numerous functionalities. In this article we have covered some of the common uses of this tool. If you would like to explore its capabilities further, please check its manual.