Package Exports
- ytranscript
- ytranscript/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ytranscript) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ytranscript
Fetch YouTube video transcripts via Innertube API. Zero API key required.
Quick Start (npx)
# No install needed!
npx ytranscript VIDEO_ID
# Or with full URL
npx ytranscript https://www.youtube.com/watch?v=dQw4w9WgXcQInstallation
# Global install
npm install -g ytranscript
# Then use directly
ytranscript VIDEO_IDCLI Usage
# Basic usage (text with timestamps)
ytranscript VIDEO_ID
# JSON format
ytranscript VIDEO_ID --format json
# SRT subtitles (save to file)
ytranscript VIDEO_ID --format srt -o subtitles.srt
# Plain text without timestamps
ytranscript VIDEO_ID --no-timestamps
# List available languages
ytranscript VIDEO_ID --list-languages
# Fetch specific language
ytranscript VIDEO_ID --lang esOutput Formats
| Format | Description |
|---|---|
text |
Plain text with timestamps (default) |
json |
Structured JSON with start, duration, text |
srt |
SubRip subtitle format |
Programmatic Usage
import { getTranscript, listLanguages } from "ytranscript";
// Get transcript
const transcript = await getTranscript("VIDEO_ID");
for (const segment of transcript) {
console.log(`[${segment.start.toFixed(1)}s] ${segment.text}`);
}
// List available languages
const languages = await listLanguages("VIDEO_ID");
for (const lang of languages) {
console.log(`${lang.code}: ${lang.name} (auto: ${lang.isAuto})`);
}
// Get transcript in specific language
const spanishTranscript = await getTranscript("VIDEO_ID", "es");Types
interface TranscriptSegment {
start: number; // Start time in seconds
duration: number; // Duration in seconds
text: string; // Transcript text
}
interface LanguageInfo {
code: string; // Language code (e.g., "en", "es")
name: string; // Language name
isAuto: boolean; // Whether auto-generated
}How It Works
- POST to Innertube API (
/youtubei/v1/player) with Android client impersonation - Extract caption track URL from response
- Fetch timedtext XML from caption URL
- Parse XML into structured segments
Uses YouTube's internal API - no authentication required.
Requirements
- Node.js 18+ (uses native
fetch)
Limitations
- May be blocked on datacenter IPs (AWS, GCP, etc.) - works fine on residential IPs
- Age-restricted videos may not work without authentication
- YouTube may change their internal API at any time
Python Version
A Python version is also available in youtube_transcript.py:
pip install requests
./youtube_transcript.py VIDEO_IDLicense
MIT