$ show iawia002/lux
Lux is a fast and simple video downloader CLI tool written in Go. It supports downloading videos, images, and audio from over 40 websites including YouTube, Bilibili, TikTok, Instagram, Twitter, and many Chinese streaming platforms. The tool operates as a single binary with a rich set of command-line options for selecting quality, downloading playlists, resuming interrupted downloads, multi-threaded downloading, and integration with aria2 for RPC-based downloads. Architecturally, Lux follows a plugin-based extractor pattern. Each supported website has its own extractor module under `extractors/`, registered via `init()` functions into a global map keyed by domain. The main entry point is `main.go`, which parses CLI flags via `urfave/cli` and dispatches to the appropriate extractor. Extracted video metadata (streams, quality, size) is passed to the downloader, which handles HTTP requests, progress bars, file merging via ffmpeg, and optional subtitle embedding. Key data flows: URL input → domain detection → extractor selection → HTML/API scraping → stream metadata extraction → downloader (single or multi-threaded) → file output. External dependencies include ffmpeg for merging and subtitle embedding, and various third-party Go libraries for HTTP requests, HTML parsing, JavaScript execution (for TikTok signing), and progress bars. The codebase is well-organized with clear separation of concerns, extensive test coverage for individual extractors, and CI workflows that run weekly to verify extractor functionality. While many extractors rely on fragile regex-based scraping of HTML pages, the overall architecture is solid and the downloader implements robust features like resume support and configurable retry logic.
The LLM identified 4 files worth highlighting for reuse:
Implements a bounded goroutine pool using a buffered channel and sync.WaitGroup. Provides Add(), Done(), and Wait() methods that mirror sync.WaitGroup but limit concurrency. The pool size can be set to any positive integer, with a default of MaxInt32 for unlimited. This is a clean, self-contained concurrency primitive that can be extracted and reused in any Go project requiring controlled parallelism.
Defines data structures for Aria2 RPC communication (Aria2RPCData and Aria2Input) and a FilePartMeta struct for tracking multi-threaded download progress. These are pure data definitions with no external dependencies, making them easily reusable in other download tools or projects that need to interface with Aria2's JSON-RPC API.
Defines the core data model for the entire application: Part, Stream, Data, CaptionPart, and the Extractor interface. Also includes Options for extraction and a FillUpStreamsData method that auto-computes stream sizes and extensions. This is a well-designed, self-contained type system that could serve as a template for any media extraction library.
Provides helper functions for HTML document parsing using goquery: GetDoc() creates a document from HTML string, GetImages() extracts image URLs by class name, and Title() extracts the page title from h1, og:title, or title tags. These are generic HTML parsing utilities that can be reused in any Go project needing web scraping functionality.