@hallelx/youtube-transcript 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,344 @@
1
+ declare class InvalidProxyConfig extends Error {
2
+ constructor(message: string);
3
+ }
4
+ declare abstract class ProxyConfig {
5
+ abstract get httpUrl(): string | undefined;
6
+ abstract get httpsUrl(): string | undefined;
7
+ get preventKeepingConnectionsAlive(): boolean;
8
+ get retriesWhenBlocked(): number;
9
+ }
10
+
11
+ interface FetchedTranscriptSnippet {
12
+ text: string;
13
+ start: number;
14
+ duration: number;
15
+ }
16
+ interface FetchedTranscriptInit {
17
+ snippets: FetchedTranscriptSnippet[];
18
+ videoId: string;
19
+ language: string;
20
+ languageCode: string;
21
+ isGenerated: boolean;
22
+ }
23
+ declare class FetchedTranscript {
24
+ readonly snippets: FetchedTranscriptSnippet[];
25
+ readonly videoId: string;
26
+ readonly language: string;
27
+ readonly languageCode: string;
28
+ readonly isGenerated: boolean;
29
+ constructor(init: FetchedTranscriptInit);
30
+ [Symbol.iterator](): IterableIterator<FetchedTranscriptSnippet>;
31
+ get length(): number;
32
+ toRawData(): Array<{
33
+ text: string;
34
+ start: number;
35
+ duration: number;
36
+ }>;
37
+ }
38
+
39
+ type FetchFn = typeof fetch;
40
+ interface HttpClientOptions {
41
+ proxyConfig?: ProxyConfig;
42
+ fetchFn?: FetchFn;
43
+ }
44
+ declare class HttpClient {
45
+ private readonly _proxyConfig?;
46
+ private readonly _userFetch?;
47
+ private readonly _cookies;
48
+ private _undiciDispatcher;
49
+ private _undiciLoaded;
50
+ constructor(options?: HttpClientOptions);
51
+ setCookie(name: string, value: string, domain: string): void;
52
+ get(url: string): Promise<Response>;
53
+ post(url: string, jsonBody: unknown): Promise<Response>;
54
+ private _fetch;
55
+ private _getUndiciDispatcher;
56
+ }
57
+
58
+ interface TranslationLanguage {
59
+ language: string;
60
+ languageCode: string;
61
+ }
62
+ interface TranscriptFetchOptions {
63
+ preserveFormatting?: boolean;
64
+ }
65
+ declare class Transcript {
66
+ readonly videoId: string;
67
+ readonly language: string;
68
+ readonly languageCode: string;
69
+ readonly isGenerated: boolean;
70
+ readonly translationLanguages: readonly TranslationLanguage[];
71
+ private readonly _httpClient;
72
+ private readonly _url;
73
+ private readonly _translationLanguagesByCode;
74
+ constructor(httpClient: HttpClient, videoId: string, url: string, language: string, languageCode: string, isGenerated: boolean, translationLanguages: readonly TranslationLanguage[]);
75
+ get isTranslatable(): boolean;
76
+ fetch(options?: TranscriptFetchOptions): Promise<FetchedTranscript>;
77
+ translate(languageCode: string): Transcript;
78
+ toString(): string;
79
+ }
80
+
81
+ interface RawCaptionTrack {
82
+ baseUrl: string;
83
+ name: {
84
+ runs: Array<{
85
+ text: string;
86
+ }>;
87
+ };
88
+ languageCode: string;
89
+ isTranslatable?: boolean;
90
+ kind?: string;
91
+ }
92
+ interface RawTranslationLanguage {
93
+ languageCode: string;
94
+ languageName: {
95
+ runs: Array<{
96
+ text: string;
97
+ }>;
98
+ };
99
+ }
100
+ interface CaptionsJson {
101
+ captionTracks: RawCaptionTrack[];
102
+ translationLanguages?: RawTranslationLanguage[];
103
+ }
104
+ declare class TranscriptList implements Iterable<Transcript> {
105
+ readonly videoId: string;
106
+ private readonly _manuallyCreated;
107
+ private readonly _generated;
108
+ private readonly _translationLanguages;
109
+ constructor(videoId: string, manuallyCreated: Map<string, Transcript>, generated: Map<string, Transcript>, translationLanguages: readonly TranslationLanguage[]);
110
+ static build(httpClient: HttpClient, videoId: string, captionsJson: CaptionsJson): TranscriptList;
111
+ [Symbol.iterator](): IterableIterator<Transcript>;
112
+ findTranscript(languageCodes: Iterable<string>): Transcript;
113
+ findGeneratedTranscript(languageCodes: Iterable<string>): Transcript;
114
+ findManuallyCreatedTranscript(languageCodes: Iterable<string>): Transcript;
115
+ private _findTranscript;
116
+ toString(): string;
117
+ }
118
+
119
+ interface YouTubeTranscriptApiOptions {
120
+ proxyConfig?: ProxyConfig;
121
+ fetchFn?: FetchFn;
122
+ }
123
+ interface FetchOptions {
124
+ languages?: Iterable<string>;
125
+ preserveFormatting?: boolean;
126
+ }
127
+ declare class YouTubeTranscriptApi {
128
+ private readonly _httpClient;
129
+ private readonly _fetcher;
130
+ constructor(options?: YouTubeTranscriptApiOptions);
131
+ list(videoId: string): Promise<TranscriptList>;
132
+ fetch(videoId: string, options?: FetchOptions): Promise<FetchedTranscript>;
133
+ }
134
+
135
+ declare class TranscriptListFetcher {
136
+ private readonly _httpClient;
137
+ private readonly _proxyConfig;
138
+ constructor(httpClient: HttpClient, proxyConfig: ProxyConfig | undefined);
139
+ fetch(videoId: string): Promise<TranscriptList>;
140
+ private _fetchCaptionsJson;
141
+ private _extractInnertubeApiKey;
142
+ private _extractCaptionsJson;
143
+ private _assertPlayability;
144
+ private _createConsentCookie;
145
+ private _fetchVideoHtml;
146
+ private _fetchHtml;
147
+ private _fetchInnertubeData;
148
+ }
149
+
150
+ declare class TranscriptParser {
151
+ private readonly _htmlRegex;
152
+ constructor(preserveFormatting?: boolean);
153
+ parse(rawData: string): FetchedTranscriptSnippet[];
154
+ }
155
+
156
+ interface GenericProxyConfigOptions {
157
+ httpUrl?: string;
158
+ httpsUrl?: string;
159
+ }
160
+ declare class GenericProxyConfig extends ProxyConfig {
161
+ protected readonly _httpUrl?: string;
162
+ protected readonly _httpsUrl?: string;
163
+ constructor(options?: GenericProxyConfigOptions);
164
+ get httpUrl(): string | undefined;
165
+ get httpsUrl(): string | undefined;
166
+ }
167
+
168
+ interface WebshareProxyConfigOptions {
169
+ proxyUsername: string;
170
+ proxyPassword: string;
171
+ filterIpLocations?: string[];
172
+ retriesWhenBlocked?: number;
173
+ domainName?: string;
174
+ proxyPort?: number;
175
+ }
176
+ declare class WebshareProxyConfig extends GenericProxyConfig {
177
+ readonly proxyUsername: string;
178
+ readonly proxyPassword: string;
179
+ readonly domainName: string;
180
+ readonly proxyPort: number;
181
+ private readonly _filterIpLocations;
182
+ private readonly _retriesWhenBlocked;
183
+ constructor(options: WebshareProxyConfigOptions);
184
+ get url(): string;
185
+ get httpUrl(): string;
186
+ get httpsUrl(): string;
187
+ get preventKeepingConnectionsAlive(): boolean;
188
+ get retriesWhenBlocked(): number;
189
+ }
190
+
191
+ declare abstract class Formatter {
192
+ abstract formatTranscript(transcript: FetchedTranscript, options?: Record<string, unknown>): string;
193
+ abstract formatTranscripts(transcripts: FetchedTranscript[], options?: Record<string, unknown>): string;
194
+ }
195
+
196
+ interface JsonFormatterOptions {
197
+ indent?: number | string;
198
+ }
199
+ declare class JSONFormatter extends Formatter {
200
+ formatTranscript(transcript: FetchedTranscript, options?: JsonFormatterOptions): string;
201
+ formatTranscripts(transcripts: FetchedTranscript[], options?: JsonFormatterOptions): string;
202
+ }
203
+
204
+ /**
205
+ * Pretty-prints a transcript using JSON.stringify with two-space indentation.
206
+ *
207
+ * Note: this differs from the Python upstream, which uses Python's `pprint`
208
+ * module (producing Python-repr style output). The TypeScript port uses
209
+ * indented JSON for the same human-readable purpose.
210
+ */
211
+ declare class PrettyPrintFormatter extends Formatter {
212
+ formatTranscript(transcript: FetchedTranscript): string;
213
+ formatTranscripts(transcripts: FetchedTranscript[]): string;
214
+ }
215
+
216
+ declare class TextFormatter extends Formatter {
217
+ formatTranscript(transcript: FetchedTranscript): string;
218
+ formatTranscripts(transcripts: FetchedTranscript[]): string;
219
+ }
220
+
221
+ declare abstract class TextBasedFormatter extends TextFormatter {
222
+ protected abstract _formatTimestamp(hours: number, mins: number, secs: number, ms: number): string;
223
+ protected abstract _formatTranscriptHeader(lines: string[]): string;
224
+ protected abstract _formatTranscriptHelper(i: number, timeText: string, snippet: FetchedTranscriptSnippet): string;
225
+ protected _secondsToTimestamp(time: number): string;
226
+ formatTranscript(transcript: FetchedTranscript): string;
227
+ }
228
+
229
+ declare class SRTFormatter extends TextBasedFormatter {
230
+ protected _formatTimestamp(hours: number, mins: number, secs: number, ms: number): string;
231
+ protected _formatTranscriptHeader(lines: string[]): string;
232
+ protected _formatTranscriptHelper(i: number, timeText: string, snippet: FetchedTranscriptSnippet): string;
233
+ }
234
+
235
+ declare class WebVTTFormatter extends TextBasedFormatter {
236
+ protected _formatTimestamp(hours: number, mins: number, secs: number, ms: number): string;
237
+ protected _formatTranscriptHeader(lines: string[]): string;
238
+ protected _formatTranscriptHelper(_i: number, timeText: string, snippet: FetchedTranscriptSnippet): string;
239
+ }
240
+
241
+ type FormatterType = 'json' | 'pretty' | 'text' | 'webvtt' | 'srt';
242
+ declare class UnknownFormatterType extends Error {
243
+ constructor(formatterType: string);
244
+ }
245
+ declare class FormatterLoader {
246
+ static readonly TYPES: Record<FormatterType, new () => Formatter>;
247
+ load(formatterType?: FormatterType | string): Formatter;
248
+ }
249
+
250
+ declare class YouTubeTranscriptApiException extends Error {
251
+ constructor(message?: string);
252
+ }
253
+ declare class CookieError extends YouTubeTranscriptApiException {
254
+ }
255
+ declare class CookiePathInvalid extends CookieError {
256
+ constructor(cookiePath: string);
257
+ }
258
+ declare class CookieInvalid extends CookieError {
259
+ constructor(cookiePath: string);
260
+ }
261
+ declare class CouldNotRetrieveTranscript extends YouTubeTranscriptApiException {
262
+ readonly videoId: string;
263
+ protected static CAUSE_MESSAGE: string;
264
+ constructor(videoId: string);
265
+ protected buildErrorMessage(): string;
266
+ get cause(): string;
267
+ toString(): string;
268
+ }
269
+ declare class YouTubeDataUnparsable extends CouldNotRetrieveTranscript {
270
+ protected static CAUSE_MESSAGE: string;
271
+ }
272
+ declare class YouTubeRequestFailed extends CouldNotRetrieveTranscript {
273
+ reason: string;
274
+ protected static CAUSE_MESSAGE: string;
275
+ constructor(videoId: string, httpError: Error | string);
276
+ get cause(): string;
277
+ }
278
+ declare class VideoUnplayable extends CouldNotRetrieveTranscript {
279
+ reason: string | null;
280
+ subReasons: string[];
281
+ protected static CAUSE_MESSAGE: string;
282
+ protected static SUBREASON_MESSAGE: string;
283
+ private _initialized;
284
+ constructor(videoId: string, reason: string | null, subReasons: string[]);
285
+ get cause(): string;
286
+ }
287
+ declare class VideoUnavailable extends CouldNotRetrieveTranscript {
288
+ protected static CAUSE_MESSAGE: string;
289
+ }
290
+ declare class InvalidVideoId extends CouldNotRetrieveTranscript {
291
+ protected static CAUSE_MESSAGE: string;
292
+ }
293
+ declare class RequestBlocked extends CouldNotRetrieveTranscript {
294
+ protected static CAUSE_MESSAGE: string;
295
+ protected static WITH_GENERIC_PROXY_CAUSE_MESSAGE: string;
296
+ protected static WITH_WEBSHARE_PROXY_CAUSE_MESSAGE: string;
297
+ private _proxyConfig;
298
+ withProxyConfig(proxyConfig: object | null | undefined): this;
299
+ get cause(): string;
300
+ }
301
+ declare class IpBlocked extends RequestBlocked {
302
+ protected static CAUSE_MESSAGE: string;
303
+ }
304
+ declare class TranscriptsDisabled extends CouldNotRetrieveTranscript {
305
+ protected static CAUSE_MESSAGE: string;
306
+ }
307
+ declare class AgeRestricted extends CouldNotRetrieveTranscript {
308
+ protected static CAUSE_MESSAGE: string;
309
+ }
310
+ declare class NotTranslatable extends CouldNotRetrieveTranscript {
311
+ protected static CAUSE_MESSAGE: string;
312
+ }
313
+ declare class TranslationLanguageNotAvailable extends CouldNotRetrieveTranscript {
314
+ protected static CAUSE_MESSAGE: string;
315
+ }
316
+ declare class FailedToCreateConsentCookie extends CouldNotRetrieveTranscript {
317
+ protected static CAUSE_MESSAGE: string;
318
+ }
319
+ declare class NoTranscriptFound extends CouldNotRetrieveTranscript {
320
+ private _requestedLanguageCodes;
321
+ private _transcriptData;
322
+ private _initialized;
323
+ protected static CAUSE_MESSAGE: string;
324
+ constructor(videoId: string, requestedLanguageCodes: Iterable<string>, transcriptData: {
325
+ toString(): string;
326
+ });
327
+ get cause(): string;
328
+ }
329
+ declare class PoTokenRequired extends CouldNotRetrieveTranscript {
330
+ protected static CAUSE_MESSAGE: string;
331
+ }
332
+
333
+ declare const WATCH_URL_TEMPLATE = "https://www.youtube.com/watch?v={video_id}";
334
+ declare const INNERTUBE_API_URL_TEMPLATE = "https://www.youtube.com/youtubei/v1/player?key={api_key}";
335
+ declare const INNERTUBE_CONTEXT: {
336
+ readonly client: {
337
+ readonly clientName: "ANDROID";
338
+ readonly clientVersion: "20.10.38";
339
+ };
340
+ };
341
+ declare function watchUrl(videoId: string): string;
342
+ declare function innertubeApiUrl(apiKey: string): string;
343
+
344
+ export { AgeRestricted, type CaptionsJson, CookieError, CookieInvalid, CookiePathInvalid, CouldNotRetrieveTranscript, FailedToCreateConsentCookie, type FetchFn, type FetchOptions, FetchedTranscript, type FetchedTranscriptInit, type FetchedTranscriptSnippet, Formatter, FormatterLoader, type FormatterType, GenericProxyConfig, type GenericProxyConfigOptions, HttpClient, type HttpClientOptions, INNERTUBE_API_URL_TEMPLATE, INNERTUBE_CONTEXT, InvalidProxyConfig, InvalidVideoId, IpBlocked, JSONFormatter, type JsonFormatterOptions, NoTranscriptFound, NotTranslatable, PoTokenRequired, PrettyPrintFormatter, ProxyConfig, RequestBlocked, SRTFormatter, TextBasedFormatter, TextFormatter, Transcript, type TranscriptFetchOptions, TranscriptList, TranscriptListFetcher, TranscriptParser, TranscriptsDisabled, type TranslationLanguage, TranslationLanguageNotAvailable, UnknownFormatterType, VideoUnavailable, VideoUnplayable, WATCH_URL_TEMPLATE, WebVTTFormatter, WebshareProxyConfig, type WebshareProxyConfigOptions, YouTubeDataUnparsable, YouTubeRequestFailed, YouTubeTranscriptApi, YouTubeTranscriptApiException, type YouTubeTranscriptApiOptions, innertubeApiUrl, watchUrl };