t-youtube-transcript-fetcher
Version:
An enhanced TypeScript library for fetching YouTube transcripts with proxy support (based on youtube-transcript)
67 lines (66 loc) • 2.15 kB
JavaScript
import { formatErrorMessage } from './utils/format.js';
/**
* Base error class for YouTube transcript errors
*/
export class TranscriptError extends Error {
constructor(message) {
super(formatErrorMessage(message));
}
}
/**
* Error thrown when YouTube's rate limit is exceeded
*/
export class RateLimitError extends TranscriptError {
constructor() {
super('⚠️ Rate Limit Exceeded\n' +
'\n' +
'YouTube is receiving too many requests from this IP.\n' +
'Please try again later or use a different IP address.');
}
}
/**
* Error thrown when the requested video does not exist or is private
*/
export class VideoUnavailableError extends TranscriptError {
constructor(videoId) {
super('🚫 Video Unavailable\n' +
'\n' +
`The video "${videoId}" is no longer available.\n` +
'It may have been removed or set to private.');
}
}
/**
* Error thrown when transcripts are disabled for the video
*/
export class TranscriptDisabledError extends TranscriptError {
constructor(videoId) {
super('❌ Transcripts Disabled\n' +
'\n' +
`Transcripts are disabled for video "${videoId}".\n` +
'The video owner has not enabled transcripts for this content.');
}
}
/**
* Error thrown when no transcripts exist for the video
*/
export class NoTranscriptError extends TranscriptError {
constructor(videoId) {
super('📝 No Transcripts Available\n' +
'\n' +
`No transcripts were found for video "${videoId}".\n` +
'This video may not have any transcripts generated yet.');
}
}
/**
* Error thrown when the requested language is not available
*/
export class LanguageNotFoundError extends TranscriptError {
constructor(lang, availableLangs, videoId) {
super('🌐 Language Not Available\n' +
'\n' +
`Transcripts in "${lang}" are not available for video "${videoId}".\n` +
'\n' +
'Available languages:\n' +
availableLangs.map(l => ` • ${l}`).join('\n'));
}
}