UNPKG

ai-youtube-transcript

Version:

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

126 lines (125 loc) 4.2 kB
import { TranscriptSnippet, LanguageInfo, TranscriptResponse } from './interfaces'; /** * Represents a fetched transcript with its snippets and metadata */ export declare class FetchedTranscript { readonly snippets: TranscriptSnippet[]; readonly videoId: string; readonly language: string; readonly languageCode: string; readonly isGenerated: boolean; /** * Creates a new FetchedTranscript instance * * @param snippets - The transcript snippets * @param videoId - The YouTube video ID * @param language - The language name * @param languageCode - The language code * @param isGenerated - Whether the transcript was auto-generated */ constructor(snippets: TranscriptSnippet[], 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: TranscriptSnippet; done: boolean; }; }; /** * Get the length of the transcript */ get length(): number; } /** * Represents a transcript with metadata */ export declare class Transcript { readonly videoId: string; readonly language: string; readonly languageCode: string; readonly isGenerated: boolean; readonly isTranslatable: boolean; readonly translationLanguages: LanguageInfo[]; private readonly baseUrl; private readonly httpClient; /** * Creates a new Transcript instance * * @param videoId - The YouTube video ID * @param language - The language name * @param languageCode - The language code * @param isGenerated - Whether the transcript is auto-generated * @param isTranslatable - Whether the transcript can be translated * @param translationLanguages - Available translation languages * @param baseUrl - The base URL for fetching the transcript * @param httpClient - The HTTP client to use for requests */ constructor(videoId: string, language: string, languageCode: string, isGenerated: boolean, isTranslatable: boolean, translationLanguages: LanguageInfo[], baseUrl: string, httpClient?: any); /** * Fetch the actual transcript data * * @param preserveFormatting - Whether to preserve HTML formatting */ fetch(preserveFormatting?: boolean): Promise<FetchedTranscript>; /** * Translate the transcript to another language * * @param languageCode - The language code to translate to */ translate(languageCode: string): Transcript; } /** * Represents a list of available transcripts for a video */ export declare class TranscriptList { private transcripts; private videoId; /** * Creates a new TranscriptList instance * * @param transcripts - The available transcripts * @param videoId - The YouTube video ID */ 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; }; }; }