Introduction
The yt-dlp is a command-line tool that let’s you download videos from thousands of websites, including YouTube. The following is a quickstart on how to download, install, and use this tool in a consistent manner.
Setup and installation
The fastest way to start using yt-dlp
is to download their binaries from their GitHub release page. Depending on your Operating System,
- For Linux/Ubuntu: use the
yt-dlp
file - For Windows: use the
yt-dlp.exe
file
Ubuntu
Once downloaded, the the file somewhere recognized by your system $PATH
variable. E.g., on Ubuntu, put it on $HOME/bin
folder; this folder is usually appended to your $PATH
variable by default (check by running echo $HOME
, or open the $HOME/.profile
file).
Then make the file executable by running:
chmod +x /path/to/yt-dlp
Important
For various tasks,
yt-dlp
depends on ffmpeg and ffprobe. And there are some bugs that preventsyt-dlp
to work correctly when using their official builds. For this, it is highly recommended to grab them from yt-dlp’s custom build of those packages from here.
Windows
Similar to Ubuntu, the .exe
binary file must be placed somewhere recognized by your system’s PATH
variable. Unlike Ubuntu, there’s no go-to directory here. What I do is, I put the path %USERPROFILE%\.local\bin
into PATH
variable, and then place all my scripts there.
To do so:
- Create the directory:
%USERPROFILE%\.local\bin
. - Press
CTRL
+PAUSE
, then click onAdvanced system settings
, and thenEnvironmental Variables
. - Edit the
Path
user variable to include%USERPROFILE%\.local\bin
. - Now place the previously downloaded
yt-dlp.exe
file into that directory.
Ensure setup is complete by running:
yt-dlp --version
Usage
Using yt-dlp
is as simple as running:
yt-dlp <url>
The above works just fine. However, we sometimes might want to have the video in certain format or with certain resolution. That’s where additional flags comes in. The below command download videos from the given URL with best quality up-to 1080p, in MKV format, and also keeps the video URL and video description in separate files:
yt-dlp -f "bestvideo[height<=1080]+bestaudio/best" --write-link --write-description --embed-thumbnail --embed-metadata --embed-subs --remux-video mkv --no-overwrites --cookies "$HOME/.config/yt-dlp/cookies.txt" --path "/path/to/download/folder" --output "./%(extractor)s/%(uploader_id)s (%(uploader)s)/%(title)s.%(ext)s"
The above was configured to work best with my setup, you should modify to adjust to your use-cases.
Notice
Notice that I’ve provided a
--cookies
flag with the command. This is because some sites and private videos require the client environment to be signed in before granting access (e.g., X (formerly Twitter)). For those cases, cookies were extracted using Get cookies.txt LOCALLY chromium extension. Learn more here.
Make it consistent
This isn’t convenient to write this long command every-time one might want to download something with this tool. This is where aliases comes in. On Ubuntu, this is as easy as appending the following into the $HOME/.bash_aliases
file:
alias dl='yt-dlp -f "bestvideo[height<=1080]+bestaudio/best" --write-link --write-description --embed-thumbnail --embed-metadata --embed-subs --remux-video mkv --no-overwrites --cookies "$HOME/.config/yt-dlp/cookies.txt" --path "/path/to/download/folder" --output "./%(extractor)s/%(uploader_id)s (%(uploader)s)/%(title)s.%(ext)s"'
Similar effect can be achieved in Windows by creating a dl.bat
file into the previously created %USERPROFILE%/.local/bin
directory with the content:
@echo off
yt-dlp -f "bestvideo[height<=1080]+bestaudio/best" --write-link --write-description --embed-thumbnail --embed-metadata --embed-subs --remux-video mkv --no-overwrites --cookies "/yt-dlp/cookies.txt" --path "/path/to/download/folder" --output "./(uploader_id)s ((title)s.%%(ext)s" %*
Now, to download videos from a URL, simply run:
dl <url>