$ show harry0703/MoneyPrinterTurbo
MoneyPrinterTurbo is a production short-video generation platform. Given a topic or script, it orchestrates LLM-based script/keyword generation, multi-provider TTS (Edge, Azure, Gemini, ElevenLabs, etc.), video material sourcing (Pexels, Pixabay, Coverr, several AI video generators), subtitle generation (Whisper or TTS timestamps), background music, and final video composition via moviepy/FFmpeg. It exposes three consistent interfaces: a FastAPI REST API, a Streamlit WebUI, and a CLI. All three share the same underlying task pipeline in `app/services/task.py`, which manages state, progress, and cross-posting to YouTube/TikTok/Instagram. The architecture is a service-oriented monolith: the core pipeline is a linear sequence of stages (script → terms → audio → subtitles → materials → video → optional BGM/cross-post). External integrations are abstracted behind provider-specific modules (e.g., `voice.py`, `material.py`, `bgm.py`). A Redis-backed or in-memory state manager tracks task progress. The configuration is runtime-editable and stored in a TOML file. The WebUI is a large Streamlit single-page application with dozens of provider-specific controls, billing confirmations, and i18n support for 12+ languages. The codebase demonstrates strong engineering practices: extensive test coverage (200+ test files), structured error handling with per-provider error classes, atomic file writes, path traversal protection, and security-conscious API key handling. However, it also shows signs of rapid growth: the WebUI is a monolithic 1300+ line script, provider integration logic is occasionally duplicated, and the dependency list is large (many third-party APIs). The repository is actively maintained with recent commits and good issue triage. It is not a research project; there are no datasets, model training, or analytical queries.
The LLM identified 4 files worth highlighting for reuse:
Defines `BaseState` abstract class with `MemoryState` and `RedisState` implementations. Used for task progress, cross-post recovery, and queue management. The interface is minimal and stable (set, get, delete, list, lock primitives). Decouples the pipeline from storage backend and is testable with the memory variant. Could be extracted into a reusable key-value store with TTL support.
Implements a filesystem-backed search result cache with SHA-256 key derivation, configurable TTL (default 24h), lock sharding for concurrent reads, and atomic `NamedTemporaryFile` + `os.replace` writes. Cache entries are provider-specific (e.g., Pexels, Pixabay) and respect duration/aspect ratio. This pattern is directly reusable for any API response caching where keys are deterministic and cache-busting by TTL is acceptable.
Provides `resolve_path_within_directory` which joins a user-supplied path to a base directory and ensures the result stays within that base using `os.path.commonpath`. Also offers a path traversal check without filesystem access and a UUID-based filename generator. This is a small, self-contained utility that solves the recurring problem of safe file I/O in web applications and can be dropped into any Python project.
Contains `LLMProviderSpec` dataclasses and a `LLM_PROVIDER_REGISTRY` dict that declaratively maps provider IDs to their configuration keys, display names, service endpoints, extra fields, and key backup companions. The UI and config validation code both iterate this registry instead of hardcoding provider lists. This pattern is reusable for any multi-provider system where providers must be discovered and configured uniformly.