UNPKG

12.1 kBTypeScriptView Raw
1declare module 'ytdl-core' {
2 import { ClientRequest } from 'http';
3 import { Readable } from 'stream';
4
5 namespace ytdl {
6 type Filter = 'audioandvideo' | 'videoandaudio' | 'video' | 'videoonly' | 'audio' | 'audioonly' | ((format: videoFormat) => boolean);
7
8 interface getInfoOptions {
9 lang?: string;
10 requestOptions?: {};
11 }
12
13 interface chooseFormatOptions {
14 quality?: 'lowest' | 'highest' | 'highestaudio' | 'lowestaudio' | 'highestvideo' | 'lowestvideo' | string | number | string[] | number[];
15 filter?: Filter;
16 format?: videoFormat;
17 }
18
19 interface downloadOptions extends getInfoOptions, chooseFormatOptions {
20 range?: {
21 start?: number;
22 end?: number;
23 };
24 begin?: string | number | Date;
25 liveBuffer?: number;
26 highWaterMark?: number;
27 dlChunkSize?: number;
28 }
29
30 interface videoFormat {
31 itag: number;
32 url: string;
33 mimeType?: string;
34 bitrate?: number;
35 audioBitrate?: number;
36 width?: number;
37 height?: number;
38 initRange?: { start: string; end: string };
39 indexRange?: { start: string; end: string };
40 lastModified: string;
41 contentLength: string;
42 quality: 'tiny' | 'small' | 'medium' | 'large' | 'hd720' | 'hd1080' | 'hd1440' | 'hd2160' | 'highres' | string;
43 qualityLabel: '144p' | '144p 15fps' | '144p60 HDR' | '240p' | '240p60 HDR' | '270p' | '360p' | '360p60 HDR'
44 | '480p' | '480p60 HDR' | '720p' | '720p60' | '720p60 HDR' | '1080p' | '1080p60' | '1080p60 HDR' | '1440p'
45 | '1440p60' | '1440p60 HDR' | '2160p' | '2160p60' | '2160p60 HDR' | '4320p' | '4320p60';
46 projectionType?: 'RECTANGULAR';
47 fps?: number;
48 averageBitrate?: number;
49 audioQuality?: 'AUDIO_QUALITY_LOW' | 'AUDIO_QUALITY_MEDIUM';
50 colorInfo?: {
51 primaries: string;
52 transferCharacteristics: string;
53 matrixCoefficients: string;
54 };
55 highReplication?: boolean;
56 approxDurationMs?: string;
57 targetDurationSec?: number;
58 maxDvrDurationSec?: number;
59 audioSampleRate?: string;
60 audioChannels?: number;
61
62 // Added by ytdl-core
63 container: 'flv' | '3gp' | 'mp4' | 'webm' | 'ts';
64 hasVideo: boolean;
65 hasAudio: boolean;
66 codecs: string;
67 videoCodec?: string;
68 audioCodec?: string;
69
70 isLive: boolean;
71 isHLS: boolean;
72 isDashMPD: boolean;
73 }
74
75 interface thumbnail {
76 url: string;
77 width: number;
78 height: number;
79 }
80
81 interface captionTrack {
82 baseUrl: string;
83 name: {
84 simpleText: 'Afrikaans' | 'Albanian' | 'Amharic' | 'Arabic' | 'Armenian' | 'Azerbaijani' | 'Bangla' | 'Basque'
85 | 'Belarusian' | 'Bosnian' | 'Bulgarian' | 'Burmese' | 'Catalan' | 'Cebuano' | 'Chinese (Simplified)'
86 | 'Chinese (Traditional)' | 'Corsican' | 'Croatian' | 'Czech' | 'Danish' | 'Dutch' | 'English'
87 | 'English (auto-generated)' | 'Esperanto' | 'Estonian' | 'Filipino' | 'Finnish' | 'French' | 'Galician'
88 | 'Georgian' | 'German' | 'Greek' | 'Gujarati' | 'Haitian Creole' | 'Hausa' | 'Hawaiian' | 'Hebrew' | 'Hindi'
89 | 'Hmong' | 'Hungarian' | 'Icelandic' | 'Igbo' | 'Indonesian' | 'Irish' | 'Italian' | 'Japanese' | 'Javanese'
90 | 'Kannada' | 'Kazakh' | 'Khmer' | 'Korean' | 'Kurdish' | 'Kyrgyz' | 'Lao' | 'Latin' | 'Latvian' | 'Lithuanian'
91 | 'Luxembourgish' | 'Macedonian' | 'Malagasy' | 'Malay' | 'Malayalam' | 'Maltese' | 'Maori' | 'Marathi'
92 | 'Mongolian' | 'Nepali' | 'Norwegian' | 'Nyanja' | 'Pashto' | 'Persian' | 'Polish' | 'Portuguese' | 'Punjabi'
93 | 'Romanian' | 'Russian' | 'Samoan' | 'Scottish Gaelic' | 'Serbian' | 'Shona' | 'Sindhi' | 'Sinhala' | 'Slovak'
94 | 'Slovenian' | 'Somali' | 'Southern Sotho' | 'Spanish' | 'Spanish (Spain)' | 'Sundanese' | 'Swahili'
95 | 'Swedish' | 'Tajik' | 'Tamil' | 'Telugu' | 'Thai' | 'Turkish' | 'Ukrainian' | 'Urdu' | 'Uzbek' | 'Vietnamese'
96 | 'Welsh' | 'Western Frisian' | 'Xhosa' | 'Yiddish' | 'Yoruba' | 'Zulu' | string;
97 };
98 vssId: string;
99 languageCode: 'af' | 'sq' | 'am' | 'ar' | 'hy' | 'az' | 'bn' | 'eu' | 'be' | 'bs' | 'bg' | 'my' | 'ca' | 'ceb'
100 | 'zh-Hans' | 'zh-Hant' | 'co' | 'hr' | 'cs' | 'da' | 'nl' | 'en' | 'eo' | 'et' | 'fil' | 'fi' | 'fr' | 'gl'
101 | 'ka' | 'de' | 'el' | 'gu' | 'ht' | 'ha' | 'haw' | 'iw' | 'hi' | 'hmn' | 'hu' | 'is' | 'ig' | 'id' | 'ga' | 'it'
102 | 'ja' | 'jv' | 'kn' | 'kk' | 'km' | 'ko' | 'ku' | 'ky' | 'lo' | 'la' | 'lv' | 'lt' | 'lb' | 'mk' | 'mg' | 'ms'
103 | 'ml' | 'mt' | 'mi' | 'mr' | 'mn' | 'ne' | 'no' | 'ny' | 'ps' | 'fa' | 'pl' | 'pt' | 'pa' | 'ro' | 'ru' | 'sm'
104 | 'gd' | 'sr' | 'sn' | 'sd' | 'si' | 'sk' | 'sl' | 'so' | 'st' | 'es' | 'su' | 'sw' | 'sv' | 'tg' | 'ta' | 'te'
105 | 'th' | 'tr' | 'uk' | 'ur' | 'uz' | 'vi' | 'cy' | 'fy' | 'xh' | 'yi' | 'yo' | 'zu' | string;
106 kind: string;
107 rtl?: boolean;
108 isTranslatable: boolean;
109 }
110
111 interface VideoDetails {
112 videoId: string;
113 title: string;
114 shortDescription: string;
115 lengthSeconds: string;
116 keywords: string[];
117 channelId: string;
118 isCrawlable: boolean;
119 thumbnail: {
120 thumbnails: thumbnail[];
121 };
122 averageRating: number;
123 allowRatings: boolean;
124 viewCount: string;
125 author: string;
126 isPrivate: boolean;
127 isUnpluggedCorpus: boolean;
128 isLiveContent: boolean;
129 }
130
131 interface Media {
132 category: string;
133 category_url: string;
134 game?: string;
135 game_url?: string;
136 year?: number;
137 song?: string;
138 artist?: string;
139 artist_url?: string;
140 writers?: string;
141 licensed_by?: string;
142 thumbnails: thumbnail[];
143 }
144
145 interface Author {
146 id: string;
147 name: string;
148 avatar: string;
149 verified: boolean;
150 user: string;
151 channel_url: string;
152 external_channel_url: string;
153 user_url: string;
154 subscriber_count: number;
155 }
156
157 interface MicroformatRenderer {
158 thumbnail: {
159 thumbnails: thumbnail[];
160 };
161 embed: {
162 iframeUrl: string;
163 flashUrl: string;
164 width: number;
165 height: number;
166 flashSecureUrl: string;
167 };
168 title: {
169 simpleText: string;
170 };
171 description: {
172 simpleText: string;
173 };
174 lengthSeconds: string;
175 ownerProfileUrl: string;
176 ownerGplusProfileUrl: string;
177 externalChannelId: string;
178 isFamilySafe: boolean;
179 availableCountries: string[];
180 isUnlisted: boolean;
181 hasYpcMetadata: boolean;
182 viewCount: string;
183 category: string;
184 publishDate: string;
185 ownerChannelName: string;
186 liveBroadcastDetails?: {
187 isLiveNow: boolean;
188 startTimestamp: string;
189 };
190 uploadDate: string;
191 }
192
193 interface MoreVideoDetails extends Omit<VideoDetails, 'author'>, Omit<MicroformatRenderer, 'title' | 'description'> {
194 published: number;
195 video_url: string;
196 age_restricted: boolean;
197 likes?: number;
198 dislikes?: number;
199 media: Media;
200 author: Author;
201 }
202
203 interface videoInfo {
204 iv_load_policy?: string;
205 iv_allow_in_place_switch?: string;
206 iv_endscreen_url?: string;
207 iv_invideo_url?: string;
208 iv3_module?: string;
209 rmktEnabled?: string;
210 uid?: string;
211 vid?: string;
212 focEnabled?: string;
213 baseUrl?: string;
214 storyboard_spec?: string;
215 serialized_ad_ux_config?: string;
216 player_error_log_fraction?: string;
217 sffb?: string;
218 ldpj?: string;
219 videostats_playback_base_url?: string;
220 innertube_context_client_version?: string;
221 t?: string;
222 fade_in_start_milliseconds: string;
223 timestamp: string;
224 ad3_module: string;
225 relative_loudness: string;
226 allow_below_the_player_companion: string;
227 eventid: string;
228 token: string;
229 atc: string;
230 cr: string;
231 apply_fade_on_midrolls: string;
232 cl: string;
233 fexp: string[];
234 apiary_host: string;
235 fade_in_duration_milliseconds: string;
236 fflags: string;
237 ssl: string;
238 pltype: string;
239 enabled_engage_types: string;
240 hl: string;
241 is_listed: string;
242 gut_tag: string;
243 apiary_host_firstparty: string;
244 enablecsi: string;
245 csn: string;
246 status: string;
247 afv_ad_tag: string;
248 idpj: string;
249 sfw_player_response: string;
250 account_playback_token: string;
251 encoded_ad_safety_reason: string;
252 tag_for_children_directed: string;
253 no_get_video_log: string;
254 ppv_remarketing_url: string;
255 fmt_list: string[][];
256 ad_slots: string;
257 fade_out_duration_milliseconds: string;
258 instream_long: string;
259 allow_html5_ads: string;
260 core_dbp: string;
261 ad_device: string;
262 itct: string;
263 root_ve_type: string;
264 excluded_ads: string;
265 aftv: string;
266 loeid: string;
267 cver: string;
268 shortform: string;
269 dclk: string;
270 csi_page_type: string;
271 ismb: string;
272 gpt_migration: string;
273 loudness: string;
274 ad_tag: string;
275 of: string;
276 probe_url: string;
277 vm: string;
278 afv_ad_tag_restricted_to_instream: string;
279 gapi_hint_params: string;
280 cid: string;
281 c: string;
282 oid: string;
283 ptchn: string;
284 as_launched_in_country: string;
285 avg_rating: string;
286 fade_out_start_milliseconds: string;
287 midroll_prefetch_size: string;
288 allow_ratings: string;
289 thumbnail_url: string;
290 iurlsd: string;
291 iurlmq: string;
292 iurlhq: string;
293 iurlmaxres: string;
294 ad_preroll: string;
295 tmi: string;
296 trueview: string;
297 host_language: string;
298 innertube_api_key: string;
299 show_content_thumbnail: string;
300 afv_instream_max: string;
301 innertube_api_version: string;
302 mpvid: string;
303 allow_embed: string;
304 ucid: string;
305 plid: string;
306 midroll_freqcap: string;
307 ad_logging_flag: string;
308 ptk: string;
309 vmap: string;
310 watermark: string[];
311 dbp: string;
312 ad_flags: string;
313 html5player: string;
314 formats: videoFormat[];
315 related_videos: relatedVideo[];
316 no_embed_allowed?: boolean;
317 player_response: {
318 playabilityStatus: {
319 status: string;
320 };
321 streamingData: {
322 expiresInSeconds: string;
323 formats: {}[];
324 adaptiveFormats: {}[];
325 };
326 captions?: {
327 playerCaptionsTracklistRenderer: {
328 captionTracks: captionTrack[];
329 };
330 };
331 microformat: {
332 playerMicroformatRenderer: MicroformatRenderer;
333 };
334 videoDetails: VideoDetails;
335 };
336 videoDetails: MoreVideoDetails;
337 }
338
339 interface relatedVideo {
340 id?: string;
341 title?: string;
342 author?: string;
343 length_seconds?: string;
344 iurlmq?: string;
345 short_view_count_text?: string;
346 session_data: string;
347 endscreen_autoplay_session_data?: string;
348 iurlhq?: string;
349 playlist_iurlhq?: string;
350 playlist_title?: string;
351 playlist_length?: string;
352 playlist_iurlmq?: string;
353 video_id?: string;
354 list?: string;
355 thumbnail_ids?: string;
356 }
357
358 function getBasicInfo(url: string, options?: getInfoOptions): Promise<videoInfo>;
359 function getInfo(url: string, options?: getInfoOptions): Promise<videoInfo>;
360 function downloadFromInfo(info: videoInfo, options?: downloadOptions): Readable;
361 function chooseFormat(format: videoFormat | videoFormat[], options?: chooseFormatOptions): videoFormat | never;
362 function filterFormats(formats: videoFormat | videoFormat[], filter?: Filter): videoFormat[];
363 function validateID(string: string): boolean;
364 function validateURL(string: string): boolean;
365 function getURLVideoID(string: string): string | never;
366 function getVideoID(string: string): string | never;
367 }
368
369 function ytdl(link: string, options?: ytdl.downloadOptions): Readable;
370
371 export = ytdl;
372}
373
\No newline at end of file