Mastering YouTube Video Downloads in Linux with youtube-dl

Learn how to download YouTube videos in Linux command line using youtube-dl, a Python-based command-line tool that allows downloading videos from YouTube and other popular video websites.
Mastering YouTube Video Downloads in Linux with youtube-dl
Photo by Alex Rodríguez Santibáñez on Unsplash

Download YouTube Videos in Linux Command Line Using youtube-dl

As a Linux user, I’ve always been fascinated by the power of command-line tools. One such tool that has caught my attention is youtube-dl, a Python-based command-line tool that allows you to download videos from YouTube, Dailymotion, Photobucket, Facebook, Yahoo, Metacafe, Depositfiles, and a few more similar sites.

What is youtube-dl?

youtube-dl is not platform-restricted, meaning it should run on any Unix, Windows, or Mac OS X-based systems. It’s written in pygtk and requires a Python interpreter to run the program.

Features of youtube-dl

  • 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 bypassing 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. However, 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.

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>

Downloading videos in Linux

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 the -F option. It will show you a list of available formats.

youtube-dl -F <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>

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>

Choosing the right audio format

In conclusion, youtube-dl is a powerful tool that allows you to download videos from YouTube and other popular video websites. With its ability to choose video formats, quality, and subtitles, it’s a must-have tool for any Linux user.