How nyniraula/whytube works
WhyTube is a Python 3.10+ CLI downloader centered around one orchestration loop in main.py. The app takes a YouTube URL from the user, reloads config.json each cycle, resolves the media, chooses the best stream combination, downloads via yt-dlp, and post-processes with FFmpeg.
The top-level boundary is simple: user input and local config on one side, YouTube/yt-dlp/FFmpeg/JS runtime dependencies on the other. There is no server, database, or persistent service layer; the repo is a single-machine download tool with filesystem output.
main.py is the control plane. It coordinates startup checks, prompts, dispatches work into the utility modules, and repeats in a loop so config changes apply to the next download without restarting. This makes the app stateful only within the current terminal session.
utils/source_handler.py appears to own configuration loading and download-directory preparation. The download target is fixed to ~/Downloads/WT_Downloads/, while outtmpl only affects the filename. That means filesystem layout is centralized and not user-directed.
utils/dependencies.py is the environment gatekeeper. It detects FFmpeg and a JavaScript runtime (Node.js or Deno), both of which are required for the download workflow to function reliably. This is an important architectural dependency because YouTube bot checks and media merging happen outside Python itself.
utils/url_resolver.py handles URL validation and metadata retrieval. Its role is the ingestion boundary between a pasted URL and structured media information from YouTube, likely via yt-dlp extraction. This is where the app distinguishes valid video or playlist sources from invalid input.
utils/format_ranking.py and utils/format_resolver.py form the selection engine. They rank available formats by resolution, codec preference, and container preference, then enforce rules like the 720p minimum for single videos and the 1080p cap for playlists. This subsystem turns raw format metadata into a concrete download plan.
utils/media_pipeline.py is the decision router. It branches by content type and config into single-video, playlist, or audio-only paths, so the rest of the app can treat “what to do” separately from “how to do it.” This is the main functional boundary in the repository.
utils/downloader.py is the execution layer around yt-dlp. It performs the actual media fetch, merge, and post-processing steps, including FFmpeg-driven muxing and AAC audio re-encoding. This is where remote media becomes local files.
Post-processing cleanup is isolated in utils/cleanup.py. Its main visible responsibility is removing leftover thumbnail artifacts after embedding, keeping the output directory clean. That makes the final filesystem state part of the app’s contract, not an accident.
utils/terminal.py is a small UX helper that clears the console, so it supports the CLI flow but does not affect download logic. It is an auxiliary boundary, not a core subsystem.
The repository’s external integration points are all local tooling and third-party services: YouTube content via yt-dlp, FFmpeg for merging and encoding, and Node.js/Deno for runtime support during extraction. The Python package metadata in pyproject.toml and lockfile in uv.lock indicate uv-managed dependency resolution, but the runtime architecture remains a single-process CLI pipeline.
Main entry points: main.py Main loop · downloader.py Downloader · dependencies.py Dependency check · media_pipeline.py Media router
Components 16
CLI control plane
Top-level orchestration and user-facing entrypoint.
- Main loop · Terminal entrypoint that reloads config, prompts the user, and coordinates each download cycle.
main.py - Terminal UI · Clears the console to keep the session readable.
utils/terminal.py
Ingestion
Configuration, URL validation, and environment checks.
- Config source · Loads config and prepares the fixed download directory.
utils/source_handler.py - Dependency check · Detects required local tools such as FFmpeg and a JavaScript runtime.
utils/dependencies.py - URL resolver · Validates input URLs and extracts structured media metadata.
utils/url_resolver.py
Format selection
Ranking and resolving the best media formats.
- Format ranking · Scores candidate formats by resolution, codec, and container preference.
utils/format_ranking.py - Format resolver · Chooses the concrete stream combination and applies policy limits.
utils/format_resolver.py
Download pipeline
Branching, download execution, and cleanup.
- Media router · Selects the single-video, playlist, or audio-only path.
utils/media_pipeline.py - Downloader · Runs media fetch, merge, and FFmpeg post-processing.
utils/downloader.py - Cleanup · Removes leftover artifacts such as embedded thumbnails.
utils/cleanup.py
External tools
Non-Python runtime and media dependencies.
- yt-dlp · External downloader and metadata extraction engine.
- FFmpeg · External muxing and audio encoding backend.
- Node.js · Optional required JavaScript runtime for extraction support.
- Deno · Alternative JavaScript runtime for extraction support.
- YouTube · Remote media source queried through yt-dlp.
- Downloads · Local output directory and downloaded media files.
Connections 20
- Main loop → Terminal UI: clears · Maintains a readable CLI session.
- Main loop → Config source: reloads config · Re-reads config on each loop iteration.
- Main loop → Dependency check: checks tools · Verifies local runtime prerequisites before download work.
- Main loop → URL resolver: resolves input · Converts pasted URLs into structured media data.
- Main loop → Media router: dispatches · Hands control to the media workflow chosen for the content type.
- URL resolver → YouTube: fetches metadata · Extracts source information from YouTube.
- Dependency check → FFmpeg: requires · Needs FFmpeg for muxing and encoding.
- Dependency check → Node.js: accepts · Can use Node.js as a JavaScript runtime.
- Dependency check → Deno: accepts · Can use Deno as a JavaScript runtime.
- Media router → Format ranking: ranks · Scores available formats before selection.
- Media router → Format resolver: selects · Applies policy and chooses the download plan.
- Format resolver → Format ranking: uses · Depends on ranking output to compare candidates.
- Format resolver → yt-dlp: drives · Consumes extractor format metadata and download options.
- Media router → Downloader: executes · Hands off the chosen path to the download layer.
- Downloader → yt-dlp: wraps · Uses yt-dlp for fetching and merging media.
- Downloader → FFmpeg: invokes · Uses FFmpeg for muxing and audio re-encoding.
- Downloader → Downloads: writes output · Stores downloaded files under the local download directory.
- Downloader → Cleanup: post-processes · Cleans artifacts after embedding and merge steps.
- Cleanup → Downloads: cleans · Removes leftover files from the output directory.
- Config source → Downloads: prepares · Ensures the fixed download directory exists.