yt-dlp
yt-dlp is a command-line audio/video downloader. It’s a fork of youtube-dl. Installation instructions can be found here.
Note: Sad thing about downloading from YouTube is, yt-dlp requires a whole Javascript runtime to solve JS challenges. You have to install deno. Plus, you sometimes need --remote-components ejs:github along with the command to get the challenge solver scripts from time to time.
Download
Download a video
yt-dlp <link>Downloads bestvideo+bestaudio.
Download audio only
yt-dlp -x <link> # short for --extract-audioList Video/Audio Formats
yt-dlp -F <link>The result would be something like this: (obviously shortened)
ID EXT RESOLUTION FPS CH │ FILESIZE TBR PROTO │ VCODEC VBR ACODEC ABR ASR MORE INFO
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
140 m4a audio only 2 │ 257.91MiB 129k https │ audio only mp4a.40.2 129k 44k [en] medium, m4a_dash
251 webm audio only 2 │ 284.16MiB 143k https │ audio only opus 143k 48k [en] medium, webm_dash
160 mp4 256x144 30 │ 43.48MiB 22k https │ avc1.4d400c 22k video only 144p, mp4_dash
278 webm 256x144 30 │ 89.44MiB 45k https │ vp9 45k video only 144p, webm_dash
399 mp4 1920x1080 30 │ 794.01MiB 399k https │ av01.0.08M.08 399k video only 1080p, mp4_dash
271 webm 2560x1440 30 │ 2.71GiB 1392k https │ vp9 1392k video only 1440p, webm_dash
400 mp4 2560x1440 30 │ 2.14GiB 1099k https │ av01.0.12M.08 1099k video only 1440p, mp4_dashNotice the IDs at the beginning. You can use it to download specific ones.
Download video of a specific resolution and/or codec
Quoting from the previous example, suppose I want to download the 1440p AV1 video along with OPUS audio. You could take note of the IDs and download the video like this:
yt-dlp -f 400+251 <link>You could use bestvideo and bestaudio as well.
Batch download from a file with URLs
Suppose you have a .txt file with a bunch of links in it:
https://example.com/video1.mp4
https://example.com/video2.mp4
https://example.com/video3.mp4
https://example.com/video4.mp4To download every video in the .txt file, you could do:
yt-dlp -a links.txtapparently, -a is short for --batch-file. (idk bro)
Chapters
Embed chapters
A lot of YouTube videos, especially the long ones, have chapters in them. Use the --embed-chapters flag.
yt-dlp --embed-chapters <link>Download chapters as separate files
yt-dlp --split-chapters "URL" -o "%(title)s - %(chapter)s.%(ext)s"Splits a video based on its chapters and saves it as separate files. Requires FFMpeg.
Get Video URL
Useful for scripting purposes.
yt-dlp -g <link>Subtitles
Download video with subtitle
yt-dlp --embed-subs <link>Download video with auto-generated subtitle
yt-dlp --write-auto-sub <link>Download subtitle only
yt-dlp --write-auto-sub --skip-download <link>