Endpoint
POST/youtube/transcript
Extracts captions from a YouTube video URL.
Request
Response (success)
Response (error)
Usage examples
curl
Node.js
Python
How it works
Camofox uses a two-tier approach:- Fast path (yt-dlp): If
yt-dlpis installed, use it to download captions directly. No browser needed. - Fallback (browser): If
yt-dlpis unavailable, launch a headless browser, play the video, and intercept the timedtext API response.
Fast path: yt-dlp
Whenyt-dlp is available (lib/youtube.js:104-187):
- Validate and normalize the YouTube URL
- Fetch video title:
yt-dlp --skip-download --print '%(title)s' <url> - Download captions:
yt-dlp --skip-download --write-sub --write-auto-sub --sub-lang <lang> --sub-format json3 <url> - Parse the downloaded
.json3,.vtt, or.srv3file - Format as timestamped text:
[MM:SS] <text>
- Fast (no browser launch)
- No ad pre-rolls
- Works for age-restricted videos (if yt-dlp supports it)
- Requires
yt-dlpbinary installed
Fallback: browser intercept
Whenyt-dlp is not installed (server.js:736-814):
- Create a temporary browser session (
__yt_transcript__) - Navigate to the video URL
- Inject script to mute audio:
video.volume = 0; video.muted = true - Register response listener for
/api/timedtextrequests - Play the video to trigger caption loading
- Intercept the caption response (JSON3, VTT, or XML format)
- Parse and format the transcript
- No dependencies (uses existing browser)
- Slower (browser launch + video load)
- May fail if video has long ad pre-roll
- Less reliable for age-restricted content
Language selection
YouTube videos may have multiple caption tracks:- Manual captions: Created by the uploader (high quality)
- Auto-generated captions: Created by YouTube’s speech recognition (may have errors)
languages parameter specifies preferred languages in priority order:
Language codes
Use ISO 639-1 two-letter codes:en- Englishes- Spanishfr- Frenchde- Germanja- Japaneseko- Koreanzh- Chinese
en-US- English (United States)en-GB- English (United Kingdom)zh-CN- Chinese (Simplified)zh-TW- Chinese (Traditional)
Caption format parsing
Camofox supports three YouTube caption formats:JSON3 format
[00:18] ♪ We're no strangers to love ♪
VTT format (WebVTT)
[00:18] ♪ We're no strangers to love ♪
XML format (YouTube’s srv3)
[00:18] ♪ We're no strangers to love ♪
All formats are normalized to the same timestamped text output.
Installing yt-dlp
yt-dlp is an optional dependency for fast transcript extraction.macOS
Linux (Debian/Ubuntu)
Python (pip)
Docker
The Camofox Docker image includes yt-dlp by default (Dockerfile:38-40):
Detection and logging
Camofox detects yt-dlp at startup by checking common installation paths (lib/youtube.js:88-98):
yt-dlp(in PATH)/usr/local/bin/yt-dlp/usr/bin/yt-dlp
Performance
yt-dlp is ~4x faster and more reliable.
Common issues
No captions available
Cause: The video has no captions (neither manual nor auto-generated). Fix: Check the video on youtube.com. If the CC button is grayed out, no captions exist.Browser fallback timeout
Cause: Video has a long ad pre-roll, or page failed to load. Fix: Install yt-dlp to skip browser-based extraction.Language not found
Cause: Requested language is unavailable. Fix: Check available languages in the error response (available_languages field in browser fallback), or request en as fallback.
yt-dlp not detected
Cause: Binary not in PATH or not executable. Fix: Install yt-dlp using the instructions above, or add its location to PATH.Security considerations
The YouTube transcript endpoint validates URLs to prevent SSRF attacks (lib/youtube.js:32-57):
- Only
http://andhttps://schemes allowed - Only
youtube.com,*.youtube.com, andyoutu.behosts allowed - URL is normalized and parsed before passing to yt-dlp
lib/youtube.js:21-29) to prevent environment variable injection: