yt-download
Take a URL, show the user the qualities that really exist for it, and download the one they choose.
Script paths below are relative to this skill directory. Run them from here, or prefix them with the skill's own path.
Step 1: Check the tools
bash scripts/check_deps.shThe last status: line says ready or missing: ....
ffmpeg matters as much as yt-dlp. Above 1080p, YouTube sends video and
audio as two separate streams, and only ffmpeg can merge them. Without ffmpeg
the user silently gets 1080p or less.
If anything is missing, run the installer:
bash scripts/check_deps.sh --installThe script picks the right installer for the OS: Homebrew on macOS, pipx or
pip on Linux, winget or scoop on Windows. It never calls sudo, because a
password prompt would hang. It prints manual step: lines instead. Pass those
lines to the user and wait for them to run those commands.
The script also warns when yt-dlp is more than 90 days old. Sites change often
and a stale yt-dlp breaks. Offer the upgrade before downloading:
brew upgrade yt-dlp on macOS, or re-run the install command on Linux and
Windows.
Step 2: List the real qualities
Never guess what a video offers. A 4K upload and a 480p upload take the same command, so read the formats first:
python3 scripts/list_qualities.py "URL"It prints one row per resolution, with the codec and the true download size:
resolution fps codec container approx size
2160p 60 av1 mp4 2.16 GiB
1080p 60 av1 mp4 420.74 MiB
audio only - aac m4a 15.28 MiB
max_height: 2160If python3 is missing, fall back to yt-dlp -F "URL" and read the table.
If the script says the URL is a playlist or channel, go to "Playlists and channels" below.
Step 3: Ask which quality
Use AskUserQuestion. It holds four options, so build them from the rows that exist, best first:
- the highest resolution, labelled with its real size, e.g.
2160p60 (2.16 GB) 1080p60if the video has it720pfor a small fileAudio only (m4a)
Put the size in every label. A user who sees 2.16 GB makes a different
choice than one who sees 4K. Skip rows the video does not have rather than
offering a resolution that will silently fall back.
Skip the question and go straight to the download when the user already named a quality in their request, such as "get this in 4K" or "just the audio".
Step 4: Download
Run the command from the folder the user wants the file in. Ask where to save it if the working directory is not an obvious fit.
Highest available quality:
yt-dlp -f "bv*+ba/b" -S "res,fps,vcodec:av01,acodec:aac,br" --merge-output-format mp4/mkv "URL"A chosen resolution, for example 1080p:
yt-dlp -f "bv*[height<=1080]+ba/b[height<=1080]" -S "res,fps,vcodec:av01,acodec:aac,br" --merge-output-format mp4/mkv "URL"Audio only:
yt-dlp -f "ba" -x --audio-format m4a "URL"Why these flags:
-f "bv*[height<=H]+ba"sets a hard ceiling.-S res:Honly prefers a height and can go above it, which surprises a user who asked for a small file.-S vcodec:av01prefers AV1. It is the only codec above 1080p that fits an mp4 container, so the file stays playable in QuickTime and most editors.-S acodec:aacavoids Opus audio, which mp4 accepts but QuickTime will not play.--merge-output-format mp4/mkvwrites mp4 when the codecs allow it, and falls back to mkv instead of producing a file that will not play.
Report the real result when it finishes: the file name, the resolution and the
size. Confirm it with ffprobe if the user cares about the exact codec:
ffprobe -v error -show_entries stream=codec_name,width,height -of default=noprint_wrappers=1 "FILE"Part of a video
A user who wants one moment out of a two hour stream does not need the whole
file. --download-sections fetches only that range, which turns a 2 GB
download into a 100 MB one.
yt-dlp --download-sections "*1:12:30-1:15:00" --force-keyframes-at-cuts \
-f "bv*+ba/b" -S "res,fps,vcodec:av01,acodec:aac,br" \
--merge-output-format mp4/mkv "URL"The * marks a plain timestamp range. Times take HH:MM:SS, MM:SS or bare
seconds, and inf means the end of the video, as in "*1:12:30-inf". Pass the
flag more than once for several ranges in one run, and each range becomes its
own file.
--force-keyframes-at-cuts gives the user the exact frame they named, but it
costs a re-encode. yt-dlp hands the section to ffmpeg, which writes it with its
default h264 encoder, so the codec preferences above do not survive the cut. A
measured 10 second section of an AV1 source came back as h264 and exactly
10.000 seconds long. The same cut without the flag stayed AV1 and ran 10.009
seconds, because yt-dlp cut at the nearest keyframe instead.
Choose by what the user needs:
- Frame-accurate start, and h264 is good enough: keep the flag.
- Original codec, and a second of slack is fine: drop it.
Setting --postprocessor-args does not change the encoder for this cut, so do
not offer it as a way to have both. The height ceiling does hold either way, so
a section of a 4K video is still 4K.
For a stream that is still running, --live-from-start begins at the opening
instead of the current moment:
yt-dlp --live-from-start -f "bv*+ba/b" -S "res,fps,vcodec:av01,acodec:aac,br" "URL"Expect it to be slow. yt-dlp collects every fragment the live server has published so far, one at a time.
Step 5: Offer an edit-friendly copy
Skip this step unless the user says they will edit the file. For someone who only wants to watch it, the download is already finished work.
Editing is different. Apple Silicon has no hardware decoder for VP9, so a 4K60 VP9 file decodes on the CPU. On an editing timeline that means dropped frames and a scrub that stutters, even on a fast machine. AV1 decodes in hardware on M3 and later, but not on M1 or M2.
A transcode trades disk space for smooth playback:
ffmpeg -i "INPUT" -c:v hevc_videotoolbox -q:v 55 -tag:v hvc1 -c:a copy "OUTPUT-edit.mp4"HEVC decodes in hardware on every Apple Silicon Mac. -q:v runs from 1 to 100,
and 55 holds up well at 4K. The -tag:v hvc1 flag is not optional. Without it
ffmpeg writes the hev1 tag, and QuickTime and Final Cut refuse the file even
though the video inside is sound.
Some ffmpeg builds reject -q:v on this encoder. Give it a bitrate instead:
ffmpeg -i "INPUT" -c:v hevc_videotoolbox -b:v 40M -tag:v hvc1 -c:a copy "OUTPUT-edit.mp4"For heavy grading or effects work, ProRes is the safer intermediate. It is roughly ten times larger than HEVC, so check the free disk space first:
ffmpeg -i "INPUT" -c:v prores_ks -profile:v 3 -pix_fmt yuv422p10le -c:a pcm_s16le "OUTPUT-edit.mov"Profile 3 is ProRes 422 HQ. Keep the original download either way. A transcode loses quality, and the edit copy cannot give it back.
Things that go wrong
Only 1080p offered on a video that should have 4K. ffmpeg is missing, or the user is looking at h264 rows. YouTube drops h264 above 1080p, so anything larger is VP9 or AV1 only.
4K missing on a video that just finished streaming. YouTube publishes the renditions one at a time, and the big ones land last. A stream that ended an hour ago may offer nothing above 1080p, with 1440p and 2160p appearing hours later. The formats list is the truth here. Tell the user the resolution does not exist yet and offer to try again later. Quietly stepping down to 1080p and calling it 4K is the one outcome to avoid.
HTTP 429 on subtitles. YouTube rate-limits caption requests hard and the
error can stop the whole download. Leave subtitles off unless the user asks.
When they do ask, add --write-auto-subs --sub-langs "en.*" --embed-subs and
warn them it may fail.
Private, unlisted, members-only or age-gated video. The user must be signed in. Add their browser session:
yt-dlp --cookies-from-browser chrome -f "bv*+ba/b" "URL"Swap chrome for safari, firefox or brave. Close the browser first on
some systems, because the cookie database locks.
"Sign in to confirm you're not a bot". YouTube is blocking the request.
Try --cookies-from-browser, then a browser impersonation build if it
persists: pipx install "yt-dlp[default,curl-cffi]".
The user has a config file. ~/.config/yt-dlp/config on macOS and Linux
sets defaults for every run. Command line flags win over it, so the commands
above still hold, but its -o template decides the file name. Read it when a
file lands somewhere unexpected.
Their own channel, and they want the master file. yt-dlp can only fetch the copy YouTube re-encoded for viewers. Tell them Google Takeout returns the original uploads, and that YouTube Studio's own download button caps at 720p.
Playlists and channels
A per-video quality menu makes no sense across hundreds of videos. Set one quality ceiling for the whole run instead, and keep a record so the command resumes:
yt-dlp -f "bv*[height<=1080]+ba/b[height<=1080]" -S "res,fps,vcodec:av01,acodec:aac,br" \
--merge-output-format mp4/mkv \
--download-archive archive.txt \
-o "%(upload_date>%Y-%m-%d)s - %(title)s [%(id)s].%(ext)s" \
"https://www.youtube.com/@HANDLE/videos"--download-archive records every finished video. Run the same command later
and it fetches only the new ones.
Warn the user about total size before starting. Count the videos first:
yt-dlp --flat-playlist --print "%(title)s" "URL" | wc -lCredits
This skill is a wrapper around yt-dlp, which does the downloading, and ffmpeg, which merges and converts the streams. yt-dlp is a fork of youtube-dl and is public domain under the Unlicense. Neither tool is bundled here; the skill only calls them.