yt-dlp – Easily download YouTube videos in the Terminal.

Download YouTube Videos Using The Yt Dlp Tool

yt-dlp is a fork of the now-inactive YouTube-dl tool, which was primarily used to download videos from various websites, including YouTube. It is a really useful tool which allows you to download videos, audio and subtitle as well, at a specific resolution. You can use it to stream a video directly to your media player as well.

In this tutorial, we will take a look at the installation process of this tool and learn how to properly use it to download video, audio and subtitles, and we will also try to embed the metadata of the video into our download file.

Also Read – Watch YouTube videos in the Terminal using YTFZF tool

Installing yt-dlp

The installation process of this tool is really simple, just open a Terminal and type the following commands regardless of which distribution you use :

sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp
Installing Yt-dlp
Installing yt-dlp

Once the installation is finished, you can start using it, the usage is discussed in the next section.

Using the yt-dlp tool

Just like any other command on Linux, this one too follows the command [options] format. To download a video, type :

yt-dlp -f 'bv*+ba' https://www.youtube.com/watch?v=aqz-KE-bpKQ

Here, the -f argument signifies ‘format’. This command will automatically download the best quality video and audio format available for this particular video. However, to download this video in a specific quality, let’s say 1080p, you can use the following arguments :

yt-dlp -f 'bv*[height=1080]+ba' https://www.youtube.com/watch?v=aqz-KE-bpKQ
Downloaded Video In 1080p Quality
Downloaded Video In 1080p Quality

As you can see in the properties of the video file, the downloaded video is in 1080p quality instead of the highest 4k.

Modify the configuration file for better usage

You can set up various kinds of defaults for this tool which it will automatically use, such as a preferred video format (mkv, mp4, webm) or SponsorBlock marking/removal etc. To create the config file, type the following in your Terminal :

# For vim editor users
sudo vim /etc/yt-dlp.conf

# For Nano editor users
sudo nano /etc/yt-dlp.conf

Once the file is created, you can add various configurations to it, for example, mine looks like this :

My Configuration File
My Configuration File

Save and exit in the vim editor by pressing the escape key and type :wq to exit, in the nano editor press Ctrl+O and Ctrl+X. Using the above configuration, yt-dlp will automatically embed thumbnail, metadata, English subtitles and SponsorBlock segments into the video automatically. And due to the first line, the video will be renamed to Title.extension instead of Title-URL.extension which is the default. –merge-output-format mkv option will download the video directly into mkv format.

The Metadata Is Embedded Into The Video
The Metadata Is Embedded Into The Video

When you play the video via the command line, you can see all the metadata associated with the video.

One more thing, you can play with is the bashrc file of your system to avoid typing big commands every time. Open .bashrc file by typing :

# For Vim users
vim ~/.bashrc

# For Nano Users
nano ~/.bahsrc

I’ve set the following alias, you can add it too :

Alias For Better Usage
Alias For Better Usage

Now, when I type ytdl <Link>, the first command will be executed along with all the configurations we’ve set in the config file. And audio command will download the audio from a link into a mp3 container. Don’t forget to refresh the bashrc file by typing :

source .bashrc

The final result should look something like this :

Embedding Metadata Subtitles Etc In The Video
Embedding Metadata Subtitles Etc In The Video

Summary

There are more cool features available for this tool which I have not described here, you can check out official GitHub page of this project for more information. Of course, there is a question of whether downloading YouTube videos count as piracy or not. Well, if you do it for data hoarding processes and do not make any kind of profit while downloading/distributing it, I don’t think It’s wrong. However, you should check the copyright laws in your Country before making any decision.

References

yt-dlp GitHub page