$ show imputnet/cobalt
Cobalt is a privacy-focused media downloader web application with a SvelteKit frontend and Node.js/Express API backend. Users paste a URL from supported platforms (YouTube, TikTok, Instagram, Twitter/X, Vimeo, Reddit, SoundCloud, Twitch, Bilibili, and 15+ others) and receive a downloadable media file. The architecture is a monorepo with three packages: @imput/cobalt-web (static frontend), @imput/cobalt-api (processing backend), and @imput/version-info (build-time version helper). The API acts as a fancy proxy - it fetches media streams from source platforms, optionally remuxes/transcodes via FFmpeg (server-side or client-side via libav.js WebAssembly), and streams results back without ever writing to disk. The frontend handles URL input, settings management (localStorage with migration), a processing queue with Web Workers for client-side FFmpeg, i18n (EN/RU), and PWA features. Key data flows: user submits URL → API validates/matches service → extracts stream URLs → returns tunnel/redirect/picker response → frontend either streams directly, proxies via API, or processes locally via Web Workers. External dependencies: FFmpeg (via ffmpeg-static), youtubei.js for YouTube, hls-parser, undici for HTTP, Redis (optional for rate limiting), Cloudflare Turnstile (optional bot protection).
The LLM identified 9 files worth highlighting for reuse:
OPFS (Origin Private File System) storage abstraction for handling large media files in browser Web Workers. Implements chunked writing with pre-allocation, sync access handles for performance, and automatic cleanup. Falls back to memory storage when OPFS unavailable. Reusable for any web app needing efficient large-file handling in workers without blocking main thread.
FFmpeg Web Worker wrapper using libav.js (FFmpeg compiled to WebAssembly). Handles probe/render lifecycle with progress reporting, memory-aware error handling (OOM detection), and automatic retry logic for WASM initialization failures. Isolated in a worker, communicates via postMessage. Demonstrates non-trivial WASM integration with proper resource cleanup and progress streaming.
Pipeline scheduler for multi-stage media processing (fetch → remux/encode). Manages dependency graph between workers, starts next stage when dependencies resolve, handles retries, and coordinates with queue state. Single-threaded execution model prevents resource exhaustion. Clean separation from queue storage and worker implementation.
YouTube extractor using youtubei.js (InnerTube API). Handles video/audio/dub selection, codec/quality picking (up to 8K, HDR, VR, high FPS), HLS/DASH manifest parsing, and poToken/visitor_data session management for authenticated endpoints. Includes fallback logic for age-restricted/private content. Complex but well-structured service module.
Streaming proxy that forwards media from source to client with proper headers (Content-Disposition, Accept-Ranges, Content-Type, Content-Length). Uses undici for efficient HTTP pipelining, supports range requests for seeking, and implements abort-controlled cleanup. Generic enough to extract for any proxy use case.
Versioned settings migration system with declarative migrators per schema version (v3→v6). Each migrator transforms partial settings object, handling field renames, type changes, and structural reorganization. Validates against defaults before applying. Reusable pattern for any client-side settings persistence with schema evolution.
Cluster-aware secret synchronization for HMAC salts (rate limiting, stream signing). Primary generates salts, broadcasts to workers via IPC; workers receive once and cache. Prevents secret drift across processes. Clean separation of concerns with single responsibility.
Type-safe i18n setup using sveltekit-i18n with auto-discovered JSON locale files. Supports nested keys, fallback locale, dynamic loading, and structured type definitions. Loaders generated from filesystem glob. Good reference for scalable localization in SvelteKit.
Cookie manager for authenticated service access (Instagram, Twitter, YouTube, etc.). Handles cookie parsing, validation, rotation, and per-service storage. Supports multiple cookie formats (Netscape, JSON). Extensible for adding new authenticated services.