UNPKG

ai-youtube-transcript

Version:

Fetch and process transcripts from YouTube videos with support for multiple languages, translation, and formatting

140 lines (139 loc) 4.55 kB
export declare class YoutubeTranscriptError extends Error { constructor(message: any); } export declare class YoutubeTranscriptTooManyRequestError extends YoutubeTranscriptError { constructor(); } export declare class YoutubeTranscriptVideoUnavailableError extends YoutubeTranscriptError { constructor(videoId: string); } export declare class YoutubeTranscriptDisabledError extends YoutubeTranscriptError { constructor(videoId: string); } export declare class YoutubeTranscriptNotAvailableError extends YoutubeTranscriptError { constructor(videoId: string); } export declare class YoutubeTranscriptNotAvailableLanguageError extends YoutubeTranscriptError { constructor(lang: string, availableLangs: string[], videoId: string); } export interface TranscriptConfig { languages?: string[]; lang?: string; preserveFormatting?: boolean; } export interface TranscriptResponse { text: string; duration: number; offset: number; lang?: string; isGenerated?: boolean; } export interface FetchedTranscriptSnippet { text: string; start: number; duration: number; } export declare class Transcript { readonly videoId: string; readonly language: string; readonly languageCode: string; readonly isGenerated: boolean; readonly isTranslatable: boolean; readonly translationLanguages: { languageCode: string; languageName: string; }[]; private readonly baseUrl; private readonly httpClient; constructor(videoId: string, language: string, languageCode: string, isGenerated: boolean, isTranslatable: boolean, translationLanguages: { languageCode: string; languageName: string; }[], baseUrl: string, httpClient?: any); /** * Fetch the actual transcript data */ fetch(preserveFormatting?: boolean): Promise<FetchedTranscript>; /** * Translate the transcript to another language * @param languageCode The language code to translate to */ translate(languageCode: string): Transcript; } export declare class TranscriptList { private transcripts; private videoId; constructor(transcripts: Transcript[], videoId: string); /** * Find a transcript in the specified languages * @param languageCodes List of language codes in order of preference */ findTranscript(languageCodes: string[]): Transcript; /** * Find a manually created transcript in the specified languages * @param languageCodes List of language codes in order of preference */ findManuallyCreatedTranscript(languageCodes: string[]): Transcript; /** * Find an automatically generated transcript in the specified languages * @param languageCodes List of language codes in order of preference */ findGeneratedTranscript(languageCodes: string[]): Transcript; /** * Get all transcripts */ getTranscripts(): Transcript[]; /** * Implement iterator protocol */ [Symbol.iterator](): { next: () => { value: Transcript; done: boolean; }; }; } export declare class FetchedTranscript { readonly snippets: FetchedTranscriptSnippet[]; readonly videoId: string; readonly language: string; readonly languageCode: string; readonly isGenerated: boolean; constructor(snippets: FetchedTranscriptSnippet[], videoId: string, language: string, languageCode: string, isGenerated: boolean); /** * Convert to raw data format */ toRawData(): TranscriptResponse[]; /** * Get the full transcript text */ getText(): string; /** * Implement iterator protocol */ [Symbol.iterator](): { next: () => { value: FetchedTranscriptSnippet; done: boolean; }; }; /** * Get the length of the transcript */ get length(): number; } /** * Class to retrieve transcript if exist */ export declare class YoutubeTranscript { /** * Fetch transcript from YTB Video * @param videoId Video url or video identifier * @param config Get transcript in a specific language ISO */ static fetchTranscript(videoId: string, config?: TranscriptConfig): Promise<TranscriptResponse[]>; /** * Retrieve video id from url or string * @param videoId video url or video id */ private static retrieveVideoId; }