How revfactory/subtitle-pro works
Purpose and Entry Points
Subtitle Pro is a Next.js web service that generates Korean subtitles for YouTube videos, then synchronizes them as an in-player overlay. The landing flow begins at app/page.tsx; direct viewing uses /watch?v=VIDEO_ID via app/watch/page.tsx. Server work is initiated and polled through app/api/subtitles/route.ts.
Application Boundary
The project uses Next.js 16 App Router, React 19, and TypeScript. Browser components own YouTube playback, job polling, and subtitle rendering; server-side API/pipeline code owns media processing and third-party API access. The shared boundary contract is types/subtitle.ts, defining cues, job states, and job payloads. Cue timestamps are seconds, matching YouTube Player getCurrentTime().
Job API and State Lifecycle
app/api/subtitles/route.ts exposes POST job creation and GET job-status polling. It coordinates with the in-memory job registry in lib/job-store.ts; this registry tracks stages such as extracting, transcribing, translating, done, and failures. hooks/use-subtitle-job.ts repeatedly queries the API and supplies status/results to the watch UI.
Subtitle Generation Pipeline
lib/pipeline.ts orchestrates the sequential generation flow:
1. Extract audio from a YouTube video.
2. Transcribe audio into timestamped source-language segments.
3. Batch/parallel translate segments to Korean.
4. Persist and return finalized subtitle cues.
It composes lib/extract.ts, lib/transcribe.ts, and lib/translate.ts. Pipeline behavior—including cache, model, and batching settings—is centralized in lib/config.ts.
External Processing and Persistence
Audio extraction invokes local yt-dlp and ffmpeg, requiring both as host-installed system tools. lib/transcribe.ts calls AssemblyAI for speech-to-text; lib/translate.ts calls Anthropic Claude for Korean translation. API credentials are environment-provided (ASSEMBLYAI_API_KEY, ANTHROPIC_API_KEY). Completed subtitles are cached on local disk under .cache/, keyed by video ID; job state itself is process-local and is not durable across server restarts.
Watch and Playback Composition
components/watch-view.tsx assembles the viewing experience. components/youtube-player.tsx integrates the YouTube IFrame Player and emits playback time. components/subtitle-overlay.tsx selects and displays the active cue for that time, while components/subtitle-controls.tsx and lib/overlay-settings.ts manage presentation preferences. hooks/use-fullscreen.ts handles fullscreen behavior around the player/overlay boundary.
Input and Navigation Flow
components/video-id-form.tsx accepts a YouTube URL or ID and routes the user to the watch page. lib/youtube.ts normalizes or validates YouTube identifiers before pipeline usage. The resulting control flow is: user input or direct watch URL → watch UI starts/polls subtitle job → server pipeline creates/caches cues → player time drives overlay selection.
Main entry points: pipeline.ts Subtitle pipeline · route.ts Subtitle job API · watch-view.tsx Watch view · subtitle.ts Subtitle contract
Components 22
Browser UI
Client-side viewing, playback, and job polling.
- Landing page
app/page.tsx - Video ID form · Accepts a YouTube URL or video ID and navigates to watch.
components/video-id-form.tsx - Watch page · Direct entry point for /watch?v=VIDEO_ID.
app/watch/page.tsx - Watch view · Combines playback, job status, and subtitle presentation.
components/watch-view.tsx - Subtitle job hook · Creates jobs and polls status.
hooks/use-subtitle-job.ts - YouTube player · Emits YouTube playback time.
components/youtube-player.tsx - Subtitle overlay · Selects the active cue from playback time.
components/subtitle-overlay.tsx - Subtitle controls
components/subtitle-controls.tsx - Overlay settings · Stores subtitle presentation preferences.
lib/overlay-settings.ts
Server generation
API, job lifecycle, and subtitle pipeline.
- Subtitle job API · POST creates generation jobs; GET returns job status.
app/api/subtitles/route.ts - In-memory job registry · Tracks extracting, transcribing, translating, done, and failures.
lib/job-store.ts - Subtitle pipeline · Sequentially extracts, transcribes, translates, and returns cues.
lib/pipeline.ts - YouTube ID validation · Normalizes and validates video identifiers.
lib/youtube.ts - Subtitle contract · Defines cues, job states, and payloads; timestamps use seconds.
types/subtitle.ts - Audio extraction · Downloads and converts video audio.
lib/extract.ts - Speech transcription · Produces timestamped source-language segments.
lib/transcribe.ts - Korean translation · Batch-translates segments to Korean.
lib/translate.ts - Pipeline configuration · Centralizes cache, model, and batching behavior.
lib/config.ts
External dependencies
Host tools, AI services, and local cache.
- yt-dlp and ffmpeg · Required local executables for audio extraction.
- AssemblyAI · Authenticated with ASSEMBLYAI_API_KEY.
- Anthropic Claude · Authenticated with ANTHROPIC_API_KEY.
- Local subtitle cache · Completed cues under .cache/, keyed by video ID.
Connections 25
- Landing page → Video ID form: renders
- Video ID form → Watch page: navigates with video ID
- Watch page → Watch view: renders
- Watch view → Subtitle job hook: starts and reads jobs
- Subtitle job hook → Subtitle job API: POST / GET polling
- Watch view → YouTube player: hosts
- YouTube player → Subtitle overlay: playback time in seconds
- Watch view → Subtitle controls: renders
- Subtitle controls → Overlay settings: updates preferences
- Overlay settings → Subtitle overlay: presentation settings
- Subtitle job API → In-memory job registry: creates and reads state
- Subtitle job API → Subtitle pipeline: runs generation
- Subtitle job API → YouTube ID validation: validates video ID
- Subtitle job API → Subtitle contract: job payloads
- Subtitle pipeline → Local subtitle cache: reads and writes completed cues
- Subtitle pipeline → Audio extraction: 1. extract audio
- Audio extraction → yt-dlp and ffmpeg: invokes
- Subtitle pipeline → Speech transcription: 2. transcribe
- Speech transcription → AssemblyAI: speech-to-text request
- Subtitle pipeline → Korean translation: 3. translate
- Korean translation → Anthropic Claude: Korean translation request
- Subtitle pipeline → Pipeline configuration: uses settings
- Subtitle pipeline → Subtitle contract: finalizes cues
- Subtitle job hook → Subtitle contract: consumes status and cues
- Subtitle overlay → Subtitle contract: selects active cue