How anandnet/youtube_explode_dart works
Purpose and public entry point
YoutubeExplodeDart is a Dart/Flutter-compatible library for querying YouTube metadata and resolving downloadable media streams, captions, comments, playlists, channels, and search results without the official YouTube API or an API key. Consumers import lib/youtube_explode_dart.dart and create the main facade in lib/src/youtube_explode_base.dart; they must close it to release its HTTP client.
Facade and domain API surface
The root facade composes feature-specific clients into a consumer-facing API: videos, playlists, channels, and search. Each feature exposes typed IDs, immutable domain models, and paginated/list-like result abstractions rather than raw YouTube payloads.
• lib/src/youtube_explode_base.dart
• lib/src/videos/videos.dart
• lib/src/playlists/playlists.dart
HTTP and failure boundary
All communication with YouTube is centralized behind a custom HTTP layer. It encapsulates request behavior, retries, client closure, rate limits, transient failures, and translation into library-specific exceptions. This is the key boundary between unstable external responses and the typed public API.
• lib/src/reverse_engineering/youtube_http_client.dart
• lib/src/retry.dart
• lib/src/exceptions/exceptions.dart
Reverse-engineering retrieval pipeline
Feature clients obtain raw YouTube pages and internal AJAX-style responses, then page/parser classes extract structured data. The implementation intentionally depends on reverse-engineered page shapes and heuristics, making this layer the primary maintenance hotspot when YouTube changes.
• lib/src/reverse_engineering/pages/watch_page.dart
• lib/src/reverse_engineering/pages/search_page.dart
• lib/src/reverse_engineering/heuristics.dart
Video metadata, related content, and interactions
Video retrieval is orchestrated through dedicated video clients/controllers and maps watch-page data into Video. Related videos, comments, and caption APIs are separate subdomains, backed by reverse-engineered internal clients and paged result types where applicable.
• lib/src/videos/video_client.dart
• lib/src/videos/video_controller.dart
• lib/src/videos/comments/comments_client.dart
Stream resolution and download flow
For a video ID, the stream client retrieves and merges player responses from selectable YouTube client profiles, builds a typed stream manifest, and exposes byte streams for the selected stream. Manifest parsing covers muxed, audio-only, video-only, DASH, and HLS variants; callers handle persistence and any external muxing such as FFmpeg.
• lib/src/videos/streams/stream_client.dart
• lib/src/videos/streams/stream_manifest.dart
• lib/src/reverse_engineering/player/player_response.dart
Cipher and JavaScript execution boundary
Some playable stream URLs require deciphering signatures from YouTube player JavaScript. The cipher subsystem extracts operations and uses an embedded JavaScript parser/engine abstraction, with separate Dart and Flutter player-source implementations. This isolates platform/runtime-specific player acquisition from stream models.
• lib/src/reverse_engineering/cipher/cipher_operations.dart
• lib/src/js/js_engine.dart
• lib/src/reverse_engineering/player/player_source_flutter.dart
Runtime and delivery
The package runs on Dart and supports Flutter usage; it relies on direct YouTube web/player endpoints rather than official Google APIs. Generated Freezed and JSON serialization artifacts sit beside models. CI publishes/tests the Dart package through GitHub Actions.
• pubspec.yaml
• lib/src/reverse_engineering/player/player_source_dart.dart
• .github/workflows/publish.yml
Main entry points: youtube_http_client.dart YouTube HTTP client · stream_client.dart Stream client · youtube_explode_base.dart YoutubeExplode facade · video_client.dart Video client
Components 22
Public library API
- Package entry point · Consumer import surface.
lib/youtube_explode_dart.dart - YoutubeExplode facade · Composes clients and owns the closable HTTP client.
lib/src/youtube_explode_base.dart - Videos, playlists, channels, search · Typed models and paged results for public domains.
lib/src/videos/videos.dart - Playlist API
lib/src/playlists/playlists.dart
Video and streams
- Video client · Orchestrates video metadata retrieval.
lib/src/videos/video_client.dart - Video controller · Maps watch data into Video models.
lib/src/videos/video_controller.dart - Comments client · Retrieves paged comment results.
lib/src/videos/comments/comments_client.dart - Stream client · Selects player profiles and resolves playable streams.
lib/src/videos/streams/stream_client.dart - Stream manifest · Represents muxed, adaptive, DASH, and HLS streams.
lib/src/videos/streams/stream_manifest.dart
Reverse engineering
Unstable YouTube page and player integration.
- YouTube HTTP client · Centralizes endpoint requests, limits, retries, and closure.
lib/src/reverse_engineering/youtube_http_client.dart - Retry policy
lib/src/retry.dart - Library exceptions · Translates external and transient failures.
lib/src/exceptions/exceptions.dart - Watch and search pages · Extract structured data from YouTube page shapes.
lib/src/reverse_engineering/pages/watch_page.dart - Search page parser
lib/src/reverse_engineering/pages/search_page.dart - Extraction heuristics · Maintenance hotspot for changing page structures.
lib/src/reverse_engineering/heuristics.dart - Player response · Normalizes internal player payloads.
lib/src/reverse_engineering/player/player_response.dart - Cipher operations · Extracts signature operations for protected stream URLs.
lib/src/reverse_engineering/cipher/cipher_operations.dart - JavaScript engine · Executes extracted player logic.
lib/src/js/js_engine.dart
Runtime and delivery
- Platform player sources · Dart and Flutter implementations acquire player JavaScript.
lib/src/reverse_engineering/player/player_source_dart.dart - Flutter player source
lib/src/reverse_engineering/player/player_source_flutter.dart - Package manifest · Dart package with Flutter compatibility.
pubspec.yaml - Publish CI · Tests and publishes the package.
.github/workflows/publish.yml
Connections 22
- Package entry point → YoutubeExplode facade: exports
- YoutubeExplode facade → Videos, playlists, channels, search: exposes
- YoutubeExplode facade → Playlist API: exposes
- YoutubeExplode facade → YouTube HTTP client: owns / closes
- Videos, playlists, channels, search → Video client: uses
- Video client → Video controller: orchestrates
- Video client → Comments client: subdomain
- Video controller → Watch and search pages: reads
- Videos, playlists, channels, search → Search page parser: queries via
- Watch and search pages → Extraction heuristics: uses
- Search page parser → Extraction heuristics: uses
- Video client → YouTube HTTP client: requests through
- Stream client → YouTube HTTP client: requests through
- Stream client → Player response: merges
- Stream client → Stream manifest: builds
- Stream client → Cipher operations: deciphers URLs
- Cipher operations → JavaScript engine: executes via
- Cipher operations → Platform player sources: gets player JS
- Platform player sources → Flutter player source: platform variant
- YouTube HTTP client → Retry policy: applies
- YouTube HTTP client → Library exceptions: translates failures
- Package manifest → Publish CI: published by