How sanatani-hackers/ytstream works
ytstream is a stdlib-only YouTube audio stream resolver and ranged downloader. Users enter a video URL or ID through the CLI or Python API; ytstream obtains visitor data, queries configured InnerTube clients in a cascade, extracts and validates direct stream URLs, then selects a format for URL/metadata output or download. The README also documents proxy support, caching, refusal-based client exclusion, async wrappers, and optional yt-dlp fallback. Edges are limited to relationships shown in excerpts or explicitly documented; the resolver excerpt is partial, so some internal wiring is not represented.
Main entry points: resolver.py Client cascade and resolver · cli.py CLI commands · download.py Ranged downloader · http.py HTTP and proxy session
Components 14
User interfaces
- CLI commands
src/ytstream/cli.py - Python API
src/ytstream/resolver.py
Stream resolution
- Stream models and selection
src/ytstream/models.py - Client cascade and resolver
src/ytstream/resolver.py - InnerTube client configuration
src/ytstream/clients.py - Visitor ID cache
src/ytstream/visitor.py - yt-dlp fallback
src/ytstream/resolver.py - Domain errors
src/ytstream/errors.py
HTTP transport
- HTTP and proxy session
src/ytstream/http.py
Download and output
- Ranged downloader
src/ytstream/download.py - Files and formatted results
src/ytstream/download.py
Other components
- CLI or library user
- YouTube InnerTube API
- YouTube media streams
Connections 20
- CLI or library user → CLI commands: runs commands
README.md - CLI or library user → Python API: calls API
README.md - CLI commands → Client cascade and resolver: creates resolver
src/ytstream/cli.py - CLI commands → Ranged downloader: requests download
src/ytstream/cli.py - CLI commands → Stream models and selection: formats results
src/ytstream/cli.py - Python API → Client cascade and resolver: delegates resolution
src/ytstream/__init__.py - Client cascade and resolver → InnerTube client configuration: uses client configs
src/ytstream/resolver.py - Client cascade and resolver → Visitor ID cache: gets visitor ID
src/ytstream/resolver.py - Client cascade and resolver → HTTP and proxy session: sends requests
src/ytstream/resolver.py - Client cascade and resolver → Stream models and selection: builds stream data
src/ytstream/resolver.py - Client cascade and resolver → yt-dlp fallback: uses fallback
README.md - Visitor ID cache → HTTP and proxy session: fetches visitor ID
src/ytstream/visitor.py - HTTP and proxy session → YouTube InnerTube API: posts API requests
- HTTP and proxy session → YouTube media streams: probes byte ranges
README.md - Client cascade and resolver → Ranged downloader: downloads selected stream
src/ytstream/resolver.py - Ranged downloader → HTTP and proxy session: fetches byte ranges
src/ytstream/download.py - Ranged downloader → YouTube media streams: reads media bytes
src/ytstream/download.py - Ranged downloader → Files and formatted results: writes completed file
src/ytstream/download.py - Client cascade and resolver → Domain errors: raises failures
src/ytstream/resolver.py - Stream models and selection → CLI commands: returns format data
src/ytstream/cli.py