ytdown
A Rust library mirroring yt-dlp's core: resolve a media URL into structured metadata and stream formats, select a format, and download it to disk.
Quickstart
use Path;
use Ytdown;
async
Collections (playlists / channels / search)
resolve returns MediaInfo::Collection for playlists, channels, and
ytsearch: queries. Its entries field is a futures::Stream that paginates
lazily, so consume it with futures::StreamExt (next, take, collect, …).
Add futures to your Cargo.toml to bring the extension trait into scope:
[]
= "0.3"
use StreamExt;
use ;
async
Features
| Feature | Default | Description |
|---|---|---|
ffmpeg |
off | Mux separate DASH audio + video streams via the system ffmpeg binary. |
Architecture
src/
├── lib.rs # Public API: Ytdown client (builder), re-exports
├── error.rs # Error enum: Network, Extraction, Cipher, UnsupportedUrl, ...
├── types.rs # MediaInfo, Format, Thumbnail, Entry, enums (Container, ...)
├── extractor/
│ ├── mod.rs # Extractor trait + Registry (URL → extractor dispatch)
│ └── youtube/
│ ├── mod.rs # URL recognition + orchestration
│ ├── innertube.rs # InnerTube client: player/browse/search endpoints
│ ├── player.rs # JS player fetch + sig/nsig function extraction
│ └── pagination.rs # Continuation-token Stream for playlists/channels/search
├── jsi.rs # boa_engine wrapper: execute extracted cipher fns
├── download/
│ ├── mod.rs # Downloader: chunked GET, Range resume, retry/backoff
│ └── progress.rs # Progress events + callback plumbing
├── format.rs # FormatSelector: best/worst/filters
└── postprocess.rs # [feature "ffmpeg"] mux / convert via system ffmpeg
A Registry holds boxed Extractors; Ytdown::resolve dispatches to the first
matching extractor or returns Error::UnsupportedUrl. The shared reqwest::Client,
config, and caches travel through an ExtractorContext.
Testing
Unit and offline integration tests (wiremock-backed) run with:
Live tests in tests/live.rs hit the real YouTube network and are marked
#[ignore = "network"], so they are skipped by default and in CI. Run them
explicitly:
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.