How anil-matcha/ai-youtube-shorts-generator works
Purpose and entry points
This is a Python CLI/library that converts a YouTube URL or local video into ranked, rendered short-form clips. main.py is the command-line entry point; library consumers import generate_shorts from shorts_generator/__init__.py. The pipeline supports a hosted MuAPI path (api, default) and a self-hosted processing path (local).
Pipeline orchestration and mode boundary
shorts_generator/pipeline.py is the central dispatcher: it normalizes request options and routes each stage to API-backed or local implementations while preserving a common result shape: source metadata, timestamped transcript, highlight candidates, and final shorts. The mode boundary is explicit:
• shorts_generator/pipeline.py
• shorts_generator/__init__.py
• main.py
Source acquisition
Input is either a remote YouTube URL or, in local mode, a direct filesystem/file URL. API mode delegates download to MuAPI; local mode uses yt-dlp and caches downloaded source video under the configured output directory. This stage produces a video URL/path consumed by transcription and rendering.
• shorts_generator/downloader.py
• shorts_generator/local/downloader.py
• shorts_generator/muapi.py
Transcription boundary
Both modes produce a timestamped, segmented transcript with compatible downstream structure. API mode calls MuAPI’s Whisper endpoint; local mode runs faster-whisper on CPU or CUDA and reuses a newer cached SRT transcript where possible. Transcript timing is the primary contract for highlight selection and clip boundaries.
• shorts_generator/transcriber.py
• shorts_generator/local/transcriber.py
• shorts_generator/config.py
Highlight analysis and selection
shorts_generator/highlights.py owns content classification, long-video chunking, virality-oriented LLM prompting, candidate parsing, overlap deduplication, and top-N selection. Videos beyond the threshold are analyzed as overlapping chunks to avoid boundary misses. The LLM backend is MuAPI in API mode or an OpenAI/Gemini selector locally; selected candidates carry start/end times, score, title, hook, and rationale.
• shorts_generator/highlights.py
• shorts_generator/local/llm.py
• shorts_generator/pipeline.py
Clip rendering
Final selected intervals are rendered at the requested aspect ratio. API mode submits autocrop/render work to MuAPI and returns hosted clip URLs. Local mode cuts with ffmpeg and vertically reframes via OpenCV face tracking, producing MP4 files in the configured output directory.
• shorts_generator/clipper.py
• shorts_generator/local/clipper.py
• shorts_generator/muapi.py
Infrastructure and external services
API mode depends on MuAPI for asynchronous download, Whisper transcription, LLM ranking, and autocrop; shorts_generator/muapi.py provides generic submit-and-poll behavior governed by timeout/poll settings. Local mode requires ffmpeg, yt-dlp, faster-whisper, and optionally CUDA; it still calls either OpenAI or Gemini for highlight ranking. Credentials and runtime choices are environment-driven through:
• shorts_generator/config.py
• .env.example
• requirements.txt
Main entry points: pipeline.py Pipeline dispatcher · highlights.py Highlight analysis · shorts_generator/clipper.py API render adapter · local/clipper.py Local clip renderer
Components 19
Entry Points
- CLI
main.py - Library API · Exports generate_shorts.
shorts_generator/__init__.py
Pipeline Core
- Pipeline dispatcher · Normalizes options and preserves the shared pipeline result shape.
shorts_generator/pipeline.py - Runtime config · Environment-driven mode, credentials, and processing settings.
shorts_generator/config.py - Timestamped transcript · Segment timing drives highlight and clip boundaries.
- Ranked highlights · Candidates include intervals, score, title, hook, and rationale.
- Rendered shorts · Hosted URLs in API mode or local MP4 files.
- Highlight analysis · Chunks long videos, prompts the LLM, deduplicates overlaps, and selects top-N.
shorts_generator/highlights.py
Hosted API Mode
- API download adapter
shorts_generator/downloader.py - API transcription adapter
shorts_generator/transcriber.py - API render adapter
shorts_generator/clipper.py - MuAPI client · Submits and polls hosted processing jobs.
shorts_generator/muapi.py
Self-hosted Local Mode
- Local downloader · Downloads and caches remote video inputs.
shorts_generator/local/downloader.py - Local transcription · Runs faster-whisper and reuses newer cached SRT files.
shorts_generator/local/transcriber.py - Local LLM selector
shorts_generator/local/llm.py - Local clip renderer · Cuts with ffmpeg and reframes vertically using OpenCV face tracking.
shorts_generator/local/clipper.py
External Services
- MuAPI · Provides download, Whisper, ranking, and autocrop jobs.
- Local media toolchain · yt-dlp, faster-whisper, ffmpeg, OpenCV, and optional CUDA.
- OpenAI / Gemini
Connections 27
- CLI → Pipeline dispatcher: invokes
- Library API → Pipeline dispatcher: calls
- Runtime config → Pipeline dispatcher: mode and settings
- Pipeline dispatcher → API download adapter: API source path
- Pipeline dispatcher → Local downloader: local source path
- API download adapter → MuAPI client: delegates
- Local downloader → Local media toolchain: uses yt-dlp
- Pipeline dispatcher → API transcription adapter: API transcription
- Pipeline dispatcher → Local transcription: local transcription
- API transcription adapter → MuAPI client: Whisper job
- Local transcription → Local media toolchain: uses faster-whisper
- API transcription adapter → Timestamped transcript: produces
- Local transcription → Timestamped transcript: produces
- Pipeline dispatcher → Highlight analysis: analyzes transcript
- Timestamped transcript → Highlight analysis: timed segments
- Highlight analysis → MuAPI client: API ranking
- Highlight analysis → Local LLM selector: local ranking
- Local LLM selector → OpenAI / Gemini: calls
- Highlight analysis → Ranked highlights: selects
- Pipeline dispatcher → API render adapter: API rendering
- Pipeline dispatcher → Local clip renderer: local rendering
- Ranked highlights → API render adapter: clip intervals
- Ranked highlights → Local clip renderer: clip intervals
- API render adapter → MuAPI client: autocrop job
- Local clip renderer → Local media toolchain: uses ffmpeg and OpenCV
- API render adapter → Rendered shorts: hosted URLs
- Local clip renderer → Rendered shorts: MP4 files