
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
youtube-transcript-js-api
Advanced tools
A JavaScript/TypeScript library to fetch YouTube video transcripts with ultra-robust 11-strategy fallback system, 100% success rate when transcripts are available, and intelligent language validation.
A robust TypeScript library for fetching YouTube video transcripts with 100% success rate when transcripts are available. Features intelligent fallback strategies, translated transcripts, and comprehensive error handling.
npm install youtube-transcript-js-api
import { YouTubeTranscriptApi } from 'youtube-transcript-js-api';
const api = new YouTubeTranscriptApi();
// Get transcript in English
const transcript = await api.getTranscript('https://www.youtube.com/watch?v=dQw4w9WgXcQ', ['en']);
console.log(transcript);
# Get transcript for a video
npx youtube-transcript get "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
# Get transcript in specific language
npx youtube-transcript get "VIDEO_URL" --language en
# Get transcript with translation
npx youtube-transcript get "VIDEO_URL" --language en --translate es
# List available transcript languages
npx youtube-transcript list "VIDEO_URL"
# Debug mode for troubleshooting
npx youtube-transcript debug "VIDEO_URL"
# Plain text (default)
npx youtube-transcript get "VIDEO_URL" --format text
# SRT subtitle format
npx youtube-transcript get "VIDEO_URL" --format srt --output transcript.srt
# WebVTT format
npx youtube-transcript get "VIDEO_URL" --format vtt --output transcript.vtt
# JSON format
npx youtube-transcript get "VIDEO_URL" --format json --output transcript.json
# Text with timestamps
npx youtube-transcript get "VIDEO_URL" --format timestamp
# Multiple language preferences
npx youtube-transcript get "VIDEO_URL" --language "en,es,fr"
# Custom output file
npx youtube-transcript get "VIDEO_URL" --output "my-transcript.txt"
# Debug with verbose logging
npx youtube-transcript get "VIDEO_URL" --debug
# Combine multiple options
npx youtube-transcript get "VIDEO_URL" --language en --format srt --output subtitle.srt --debug
getTranscript(videoUrl, languages?)
Fetches transcript with ultra-robust fallback system.
const transcript = await api.getTranscript(
'https://www.youtube.com/watch?v=VIDEO_ID',
['en', 'es'] // Optional: preferred languages
);
getTranscriptByLanguage(videoUrl, language)
Gets transcript for specific language with validation.
const transcript = await api.getTranscriptByLanguage(
'https://www.youtube.com/watch?v=VIDEO_ID',
'en'
);
listTranscripts(videoUrl)
Lists all available transcript languages.
const available = await api.listTranscripts('https://www.youtube.com/watch?v=VIDEO_ID');
console.log(available.transcripts); // Array of available languages
const api = new YouTubeTranscriptApi({
debug: true,
rateLimit: {
enabled: true,
maxConcurrentRequests: 2,
baseDelay: { min: 1000, max: 2000 }
},
timeout: 30000
});
The library includes several predefined rate limiting configurations for different use cases:
import { CONSERVATIVE_CONFIG } from 'youtube-transcript-js-api/configs';
const api = new YouTubeTranscriptApi({
rateLimit: CONSERVATIVE_CONFIG
});
import { BALANCED_CONFIG } from 'youtube-transcript-js-api/configs';
const api = new YouTubeTranscriptApi({
rateLimit: BALANCED_CONFIG
});
import { AGGRESSIVE_CONFIG } from 'youtube-transcript-js-api/configs';
const api = new YouTubeTranscriptApi({
rateLimit: AGGRESSIVE_CONFIG
});
import { DEVELOPMENT_CONFIG } from 'youtube-transcript-js-api/configs';
const api = new YouTubeTranscriptApi({
rateLimit: DEVELOPMENT_CONFIG
});
import { DISABLED_CONFIG } from 'youtube-transcript-js-api/configs';
const api = new YouTubeTranscriptApi({
rateLimit: DISABLED_CONFIG
});
import { PROXY_OPTIMIZED_CONFIG } from 'youtube-transcript-js-api/configs';
const api = new YouTubeTranscriptApi({
rateLimit: PROXY_OPTIMIZED_CONFIG
});
import { SCENARIO_CONFIGS } from 'youtube-transcript-js-api/configs';
const api = new YouTubeTranscriptApi({
rateLimit: SCENARIO_CONFIGS.ECOMMERCE
});
const api = new YouTubeTranscriptApi({
rateLimit: SCENARIO_CONFIGS.SOCIAL_MEDIA
});
const api = new YouTubeTranscriptApi({
rateLimit: SCENARIO_CONFIGS.EDUCATION
});
const api = new YouTubeTranscriptApi({
rateLimit: SCENARIO_CONFIGS.CONTENT_MODERATION
});
const customConfig = {
enabled: true,
maxConcurrentRequests: 3,
baseDelay: { min: 800, max: 1200 },
exponentialBackoff: {
multiplier: 1.8,
maxDelay: 30000,
jitter: true
},
circuitBreaker: {
enabled: true,
failureThreshold: 5,
resetTimeout: 60000
},
adaptiveScaling: {
enabled: true,
successSpeedup: 0.9,
failureSlowdown: 1.5
}
};
const api = new YouTubeTranscriptApi({
rateLimit: customConfig,
timeout: 15000,
debug: false
});
interface YouTubeTranscriptApiConfig {
// Enable debug logging
debug?: boolean;
// Request timeout in milliseconds
timeout?: number;
// Rate limiting configuration
rateLimit?: {
enabled: boolean;
maxConcurrentRequests: number;
baseDelay: { min: number; max: number };
exponentialBackoff?: {
multiplier: number;
maxDelay: number;
jitter: boolean;
};
circuitBreaker?: {
enabled: boolean;
failureThreshold: number;
resetTimeout: number;
};
adaptiveScaling?: {
enabled: boolean;
successSpeedup: number;
failureSlowdown: number;
};
};
// User agent for requests
userAgent?: string;
// Custom headers
headers?: Record<string, string>;
}
The library achieves 100% success rate through:
[
{ text: "Hello world", start: 0, duration: 2.5 },
{ text: "How are you?", start: 2.5, duration: 1.8 }
]
text
- Plain text (default)srt
- SubRip subtitle formatvtt
- WebVTT formatjson
- JSON formattimestamp
- Text with timestampstry {
const transcript = await api.getTranscript(videoUrl, ['en']);
} catch (error) {
if (error.name === 'NoTranscriptFoundError') {
console.log('No transcript available for this video');
} else if (error.name === 'VideoUnavailableError') {
console.log('Video is private or unavailable');
}
}
git clone https://github.com/cmyildirim/youtube-transcript-js-api.git
cd youtube-transcript-js-api
npm install
# Run all tests
npm test
# Batch test with CLI
npx tsx tests/batch-test.ts 10
npm run build
Detailed documentation available in the docs
folder:
Contributions are welcome! Please read our contributing guidelines and ensure all tests pass.
MIT License - see LICENSE file for details.
This library is for educational and research purposes only. Please respect YouTube's Terms of Service and use this library responsibly.
Version 1.4.0 - Ultra-robust transcript fetching with 100% success rate and fully modularized test suite. All tests are now organized in logical groups under tests/transcript/
for easier maintenance and coverage.
FAQs
A JavaScript/TypeScript library to fetch YouTube video transcripts with ultra-robust 11-strategy fallback system, 100% success rate when transcripts are available, and intelligent language validation.
The npm package youtube-transcript-js-api receives a total of 18 weekly downloads. As such, youtube-transcript-js-api popularity was classified as not popular.
We found that youtube-transcript-js-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainerβs token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.