fetchtranscript
v0.1.0
Published
Official TypeScript/JavaScript SDK for the FetchTranscript YouTube API
Downloads
136
Maintainers
Readme
FetchTranscript JavaScript/TypeScript SDK
Official TypeScript/JavaScript SDK for the FetchTranscript API — fetch YouTube transcripts, video metadata, channel info, and more.
Installation
npm install fetchtranscriptQuick Start
import { FetchTranscriptClient } from 'fetchtranscript';
const client = new FetchTranscriptClient({ apiKey: 'yt_your_api_key' });
// Get a transcript
const transcript = await client.transcripts.get('dQw4w9WgXcQ');
for (const segment of transcript.segments) {
console.log(`[${segment.start.toFixed(1)}s] ${segment.text}`);
}
// Get video metadata
const video = await client.videos.getMetadata('dQw4w9WgXcQ');
console.log(video.title);API Reference
Transcripts
// Get transcript (JSON format with segments)
const transcript = await client.transcripts.get('VIDEO_ID');
// Get transcript in a specific language
const transcript = await client.transcripts.get('VIDEO_ID', { lang: 'es' });
// Get as plain text
const text = await client.transcripts.getText('VIDEO_ID');
// Get as SRT subtitles
const srt = await client.transcripts.getSrt('VIDEO_ID');
// List available languages
const languages = await client.transcripts.listLanguages('VIDEO_ID');Videos
// Get video metadata
const metadata = await client.videos.getMetadata('VIDEO_ID');
// Get video chapters
const chapters = await client.videos.getChapters('VIDEO_ID');
// Get video comments
const comments = await client.videos.getComments('VIDEO_ID', { limit: 50 });Channels
// Get channel info
const channel = await client.channels.getInfo('CHANNEL_ID');
// Get channel videos
const videos = await client.channels.getVideos('CHANNEL_ID', { limit: 20 });
// Get all videos with auto-pagination
const allVideos = await client.channels.getAllVideos('CHANNEL_ID');Search
// Search videos
const results = await client.search.videos('python tutorial', { limit: 10 });Error Handling
The SDK throws typed exceptions instead of generic errors:
import {
FetchTranscriptClient,
VideoNotFoundError,
InsufficientCreditsError,
AuthenticationError,
} from 'fetchtranscript';
const client = new FetchTranscriptClient({ apiKey: 'yt_your_api_key' });
try {
const transcript = await client.transcripts.get('invalid_id');
} catch (error) {
if (error instanceof VideoNotFoundError) {
console.log(`Video not found: ${error.message}`);
} else if (error instanceof InsufficientCreditsError) {
console.log('Not enough credits');
} else if (error instanceof AuthenticationError) {
console.log('Invalid API key');
}
}Exception Hierarchy
| Exception | HTTP Status | Description |
|-----------|-------------|-------------|
| FetchTranscriptError | — | Base exception |
| VideoNotFoundError | 404 | Video not found or transcripts disabled |
| ChannelNotFoundError | 404 | Channel not found |
| InvalidVideoIdError | 400 | Invalid video/channel ID format |
| InsufficientCreditsError | 402 | Not enough credits |
| AuthenticationError | 401 | Missing or invalid API key |
| ServiceUnavailableError | 503 | Upstream service unavailable |
Response Headers
After each request, you can check:
await client.transcripts.get('dQw4w9WgXcQ');
console.log(client.creditsRemaining); // Remaining API credits
console.log(client.processingTimeMs); // Processing time in msRequirements
- Node.js 18+ (uses native
fetch) - Zero runtime dependencies
License
MIT
