$ show arabcoders/ytptube
This repository is a full-stack self-hosted media download manager and library preparation layer centered on yt-dlp. The backend is implemented in Python using aiohttp, SQLite (via SQLAlchemy), and includes a structured feature-based architecture (auth, presets, tasks, conditions, downloads, streaming, notifications, ytdlp integration). The frontend is a Nuxt 3 / Vue 3 single-page application with comprehensive i18n support. Core capabilities include automated download scheduling with cron-like task definitions, conditional filtering, Cloudflare challenge solving, real-time WebSocket updates, streaming via on-the-fly HLS transcoding with hardware acceleration fallback, and a browser extension for quick URL submission. The codebase demonstrates good engineering practices: event bus for decoupled communication, singleton-based service containers, repository pattern for data access, custom migration framework, and extensive async test coverage. Notable external dependencies are yt-dlp (core downloader), ffmpeg (transcoding), curl_cffi (impersonation), and apprise (notifications). While the architecture is modular and well-organized, there is some code duplication across CRUD repositories and migration files, and tight coupling to yt-dlp internals via custom patches. The project is actively maintained with frequent commits, a large test suite, and clear containerization support.
The LLM identified 5 files worth highlighting for reuse:
Provides `Singleton` and `ThreadSafe` metaclasses for enforcing single-instance patterns across the codebase. Used by Config, EventBus, services, and repositories. Thread-safe with double-checked locking. Easily extractable for any Python project needing thread-safe singletons.
Implements an `EventBus` singleton with `subscribe`/`emit` methods, supporting both sync and async listeners. Events are typed dataclasses. Mutation between listeners and event cancellation are supported. Decouples components (e.g., download state changes, config updates) and is reusable across async systems.
A thread-safe background worker that can execute sync and async functions with a configurable queue and shutdown coordination. Handles exceptions and provides a callback mechanism. Extracted this pattern is useful for any async application needing to offload blocking operations.
Provides a `@route()` decorator that auto-registers aiohttp view handlers, supports HTTP methods, path, and permission levels (public, auth_only, cookie_only). Injects services via inspection. This pattern cleanly separates route registration from handler logic and could be reused as a lightweight routing framework.
Contains `rename_file` and `move_file` functions that automatically handle sidecar files (subtitles, thumbnails, metadata) to keep them in sync. Also implements `safe_path`, `merge_dict` (with depth/size limits and dunder key filtering), and `timed_lru_cache` decorator. These utility functions are well-tested and reusable outside the project.