youtube-dl (now yt-dlp) knowledgebase
Last updated: Sep 12 2022 | Created: Oct 30 2021
yt-dlp installation
More useful things will be added to this guide when I get to it. Since the original youtube-dl project hasn't been updated for more than 5 months now, and the fork yt-dlp offers many great new features compared to the original project I'm going to go with this now. Edit: the core maintainer has removed themselves from the youtube-dl GitHub repository. The good old youtube-dl is gone.
- Visit the Github repository.
- Click on the 'releases' button on the right side then scroll all the way down to the 'assets' part.
- If you're using GNU/Linux, just download the
yt-dlp
file, then make it executable using thechmod +x
command. After that you can simply run it:./yt-dlp --parameters
. - For Windows, I recommend you the
yt-dlp.exe
file. Simply download it then open a command prompt or powershell to run it. For example:PS C:\Users\user> .\yt-dlp --parameters
. - You'll also need ffmpeg. On Debian-based distros you can simply install it using the
apt install ffmpeg
command, on Arch dopacman -S ffmpeg
. On Windows download the executable package from the ffmpeg website then add the 3 files from thebin
folder to the PATH.
Alternatively, you can add it to the PATH so you can run it anywhere.
Now let's see those commands.
video and audio
Let's say you want to download the audio track of a youtube video, and you want to save it as mp3. You'd have to use this command: yt-dlp --extract-audio --audio-format mp3 video_URL
Now see what to use if you want to download a normal 1080p video. Using the bestvideo
tag, it will automatically choose the best available format. Using the [height=1080]
part it will choose the 1080p resolution if it is available. And also it is going to choose the best available audio quality since you used the bestaudio/best
tag. yt-dlp -i -f "bestvideo[height=1080]+bestaudio/best video_URL"
Try to play around with this command. In the next example, let's say you want to download a video in a better, than 1080p resolution, but with the worst possible audio quality.yt-dlp -i -f "bestvideo[height>=1080]+worstaudio/worst" video_URL
You can change this command so it will suit for your needs.
This morning I found a reddit thread where a random person was complaining about the basic download format of yt-dlp. If you don't like the webm
extension like them, you can add this piece of code in the end of your command: --merge-output-format mkv
. It is going to merge the available video and audio formats into mkv
.
So, the final command would look like this: yt-dlp -i -f "bestvideo[height=1080]+bestaudio/best --merge-output-format mkv video_URL
playlist
Before doing anything, I need your attention. Youtube playlist URLs have two types. The first one is the https://www.youtube.com/playlist?list=
formatted URL. There's nothing wrong about this one. You'll be able to use the following commands without any problem with this link type. But there's another type of playlist link: https://www.youtube.com/watch?v=VIDEOID&list=
. Now this link is a bit problematic, since it has an '&' inside it which counts as a special character in the shell and it will lead to problems. This issue can be solved super easily, just put the link inside quotes, like this: 'link'
. You will also see this soon in the example.
I recommend you to use the command template below to download a playlist. But there's a few other parameters I'd like to talk about.
First one is --playlist-start NUMBER
. The default value here is 1, you can change it if you want to. If you want to download the playlist from its first video, it is not necessary to define this option.
The next parameter is --playlist-end NUMBER
. You can define the last number of the video of a playlist that you want to download. The default value here is the last video, so again, it's not necessary to define this parameter if you want to download all videos from a playlist until the end.
Another useful parameter is --playlist-items
. You can define specific videos that you want to download. For example you want to download the second, the fifth and the twelfth items of a playlist. Then you would use the --playlist-items 2,5,20
. You can also specify ranges, for example: 3-5,10-12,24-27
. It is also possible to mix the specific videos and the ranges: 3-5,8,10-12,17
.
The last few commands that are worth mentioning here are in connection with the age of the video. With --date
you can select videos that were uploaded on a specific date/year. We can also modify this more, for example we can choose videos that were uploaded before a specific date/year: --datebefore 2017
, or after a specific date/year: --dateafter 2019
.
Finally, let's see an example. Imagine a playlist with a weird URL which contains a '&' sign. It has 200 music videos, and we want to download a couple of videos (21,24-29,44-56,78,109-122,143) from the20th video until the 144th video that were uploaded before 2016. I want the best possible audio and a video resolution which is not higher than 720p. And also I want to specify the -yes-playlist
option. The final command would look like this:
yt-dlp -i -f "bestvideo[height<=720]+bestaudio/best -yes-playlist --playlist-start 20 --playlist-end 144 --playlist-items 21,24-29,78,109-122,143 --datebefore 2016 'weird_URL'
advanced commands
download your liked videos
First of all, you have to export your cookies to a file called cookies.txt when visiting the youtube.com website. I recommend this extension to do that. After that, you can put that text file into a folder and then open the Terminal/PowerShell in that directory. Finally, run this command: yt-dlp.exe --ignore-errors --download-archive “archive.txt” --cookies cookies.txt "https://www.youtube.com/playlist?list=LL"
download segments of a twitch stream(vod)
ffmpeg -ss 02:00:00 -to 02:01:00 -i `yt-dlp --get-url https://www.twitch.tv/videos/12345678` output.mp4
The comment above will download a one minute video from 2 hour to 2 hour 1 min from a twitch VOD.
PSA: these commands should work on most sites that are supported by youtube-dl and yt-dlp.
Currently this is it folks, later I'll add more parameters to this guide. Hope you found this useful.
Would you like to contact me? Feel free to do it here: blog[at]perjel.hu.