Linux command line YouTube downloader with WSL and uv
With WSL, uv
, yt-dlp
.
This is the third time I have to look up how to download YouTube video using command line. It would be easier if I keep a note here.
The aim: download a certain part of YouTube video.
ffmpeg
may be required but I already have that in my system.
uv tool install yt-dlp
Now yt-dlp
will be callable anywhere in your system (environment?).
yt-dlp --download-sections "*0:43-0:47" <VIDEO_URL>
Obviously, change <VIDEO_URL>
to your target URL.
This doesn't work on some videos; I don't know why yet. Probably video formatting. Maybe you can try something like this (try to download mp4 & m4a of the video):
yt-dlp --download-sections "*0:43-0:47" -f "bv*[ext=mp4]+bestaudio[ext=m4a]/best" https://www.youtube.com/watch?v=dQw4w9WgXcQ
But it can be imperfect (e.g. video and audio not synced).
If you need certain resolution, we can use the command below. It means maximum video resolution is 1080p. If it's not available, it should download a smaller resolution.
yt-dlp --download-sections "*3:25-4:05" -f "bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best" <VIDEO_URL>