Skip to content

ytgrab v0.2.0

Choose a tag to compare

@fitzypopper fitzypopper released this 15 Nov 09:48
· 2 commits to main since this release

What this release adds

v0.1.0 could only download what YouTube's Android client handed over, and it fell back to 360p whenever that client refused a format. v0.2.0 fixes that, and adds the options people actually reach for.

High quality on every video

Some videos are only served to the TV app, and its download links carry a
throttling puzzle (n=) that has to be solved by running YouTube's player
JavaScript. yt-dlp does that by asking you to install deno, node or bun.

ytgrab embeds QuickJS instead, and vendors the
solver from yt-dlp/ejs (Unlicense), so
nothing extra needs to be installed.

$ ytgrab -f 137 "https://youtu.be/JBoUwElRFVM"
googlevideo refused format 137 (HTTP 403); retrying through the TV client
Saved ytgrab.mp4                     # 944 MB, 1920x1080

Speed

Measured on the same machine, same videos, back to back:

yt-dlp ytgrab
1080p (77 MB) 14.7 s 3.2 s
1080p (944 MB) 51.8 s 32.5 s
4K (342 MB) 25.1 s 15.9 s

Two things make the difference:

  • Parallel byte ranges. YouTube throttles a single connection to about
    250 kB/s but serves parallel Range requests at full speed.
  • 8 MiB requests. The server shapes the bandwidth of a long request:
    8 MiB chunks ran at 18.8 MB/s while 15 MiB chunks collapsed to 3.2 MB/s.
    The chunk size and the connection count were measured against each other.

Interrupted downloads

Downloads resume, and the result is byte identical to a clean download:

$ ytgrab -f 137 "https://youtu.be/JBoUwElRFVM"   # killed halfway
$ ytgrab -f 137 "https://youtu.be/JBoUwElRFVM"   # picks up where it stopped
$ sha256sum clean.mp4 resumed.mp4

A connection that dies mid-transfer is retried with the next range, and a
403 makes the chunk size smaller rather than giving up. Two instances cannot
corrupt each other: a lock file holds the pid of the process that owns the
download. All of this is covered by tests/resume.rs, which uses a local
server that drops every third connection on purpose.

New options

  • --exec / --exec-before-download — run a command per video
  • --playlist-start / --playlist-end / --playlist-items / --playlist-reverse / --playlist-random / --max-downloads / --break-on-existing
  • --download-archive — skip what you already have
  • --print and --get-title / --get-id / --get-duration / --get-uploader / --print-to-file / --skip-download
  • --match-filter, --dateafter, --datebefore, --max-filesize, --min-filesize
  • --proxy, --socket-timeout, --no-part, --sleep-requests
  • --list-subs, --write-description, --write-comments
  • --trim-filenames, --restrict-filenames, --windows-filenames
  • --config — keep your options in a file
  • --chunk-size, --fragments — tune the download
  • --no-cache-dir — ignore the session cache

Also

  • The session (watch page, player script, challenge solver) is cached in
    ~/.cache/ytgrab/, which saves about six seconds and 3.9 MB of traffic on
    every run after the first.
  • The video and audio streams are fetched at the same time.
  • A download that stops early is reported instead of being muxed into a
    broken file.

Installing

cargo install --git https://github.com/fitzypopper/ytgrab-rs

or grab the Linux binary from the assets below. ffmpeg is needed for
muxing and audio extraction.


This is an independent implementation. It is not affiliated with, endorsed by,
or a port of yt-dlp, which stays the more
feature complete tool — it supports roughly 1755 sites against ytgrab's one.