-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.d.ts
288 lines (256 loc) · 8.43 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import { Readable } from "stream";
import { EventEmitter } from "events";
import { Cookie as ToughCookie } from "tough-cookie";
import { HttpsCookieAgent, HttpCookieAgent } from "http-cookie-agent/http";
import { Agent as HttpsAgent } from "https";
import { Agent as HttpAgent } from "http";
type HttpsCookieAgentOptions = ConstructorParameters<typeof HttpsCookieAgent>[0];
type HttpCookieAgentOptions = ConstructorParameters<typeof HttpCookieAgent>[0];
type convert = string | boolean;
type download = string | object;
type CookieType = [Cookie | {
key?: string;
name?: string;
value?: string;
domain: string;
httpOnly?: boolean;
hostOnly?: boolean;
secure?: boolean;
path?: string;
expires?: string;
expirationDate?: string;
sameSite?: string;
}]
type streamType = "audio" | "video";
type quality = "high" | "low" | number;
interface downloadOptions{
type: streamType;
highWaterMark: number;
quality: quality;
download: boolean;
}
interface Stream extends EventEmitter{
stream: Readable;
url: string;
container: string;
video_url: string;
quality: number;
bytes_count: number;
content_length: string;
duration: number;
type: string;
req_type: string;
mimeType: string;
format: {
itag: number;
mimeType: string;
bitrate: number;
width: number;
height: number;
lastModified: string;
contentLength: string;
quality: string;
fps: number;
qualityLabel: string;
projectionType: string;
avarageBitrate: number;
audioQuality: string;
approxDurationMs: string;
audioSampleRate: string;
audioChannels: number;
signatureCipher: string;
codec: string;
container: string;
};
info: YouTubeData;
/**
* Destroys the stream and stops downloading the audio if a download was still going on
*/
destroy() : void;
}
interface YouTubeData{
id: string;
url: string;
author: string;
title: string;
description: string;
embed_url: string;
family_safe?: boolean;
available_countries?: [string];
category?: string;
thumbnails: [{url: string, width: number, height: number}];
default_thumbnail: {url: string, width: number, height: number};
uploaded?: string;
uploadedTimestamp?: number;
duration: number;
views: number;
views_text: string;
channel: {
author: string;
id: string;
url: string;
};
formats: [{
itag?: number;
mimeType?: string;
bitrate?: number;
width?: number;
height?: number;
lastModified?: string;
contentLength?: string;
quality?: string;
fps?: number;
qualityLabel?: string;
projectionType?: string;
avarageBitrate?: number;
audioQuality?: string;
approxDurationMs?: string;
audioSampleRate?: string;
audioChannels?: number;
signatureCipher?: string;
codec?: string;
container?: string;
url?: string;
}];
html5player?: string;
user_agent: string;
cookie: string;
}
interface Video{
id: string;
url: string;
title: string;
author: string;
channel_id?: string;
channel_url?: string;
length_text: string;
length: number;
views_text: string;
views: number;
thumbnail: string;
user_agent: string;
cookie: string | null;
}
interface PlaylistVideo{
title: string;
video_url: string;
video_id: string;
position?: number;
length_text?: string;
length: number;
thumbnails: [{url: string, height: number, width: number}];
default_thumbnail: {url: string, height: number, width: number};
playlist_id: string;
playlist_url: string;
}
interface Playlist{
title: string;
description: string;
author: string;
author_images: [{url: string, height: number, width: number}];
default_author_images?: {url: string, height: number, width: number};
author_channel: string;
url: string;
videos: [PlaylistVideo],
videos_amount: number;
cookie: string | null;
user_agent: string;
}
/**
* Get information about a song
* @param url The YouTube url of the song
* @param boolean A boolean which defines whether the package should force send a request to YouTube to receive the data or whether it can use cached data as well
*/
export declare function getInfo(url: string, force?: boolean) : Promise<YouTubeData>;
/**
* Check whether the YouTube video ID is valid or not
* @param id The YouTube video ID
*/
export declare function validateID(id: string) : boolean;
/**
* Check whether the YouTube URL is valid or not
* @param url The YouTube URL
*/
export declare function validateURL(url: string) : boolean;
/**
* Check whether the YouTube video URL is valid or not
* @param url The YouTube video URL
*/
export declare function validateVideoURL(url: string) : boolean;
/**
* Check whether the YouTube playlist URL is valid or not
* @param url The YouTube playlist URL
*/
export declare function validatePlaylistURL(url: string) : boolean;
/**
* Check whether the YouTube playlist ID is valid or not
* @param id The YouTube playlist ID
*/
export declare function validatePlaylistID(id: string) : boolean;
/**
* Get the YouTube video ID from the video URL
* @param url The YouTube video URL
*/
export declare function getID(url: string) : convert;
/**
* Get the YouTube video URL from the video ID
* @param id The YouTube video ID
*/
export declare function getURL(id: string) : convert;
/**
* Search for YouTube video's
* @param query The search query to search a video
*/
export declare function search(query: string) : Promise<[Video]>;
/**
* Download the YouTube video and create a readable stream of it
* @param info Either the YouTube url of the video or the received information from the getInfo function
* @param options An object that defines options which the stream function should take into account
*/
export declare function stream(info: download, options: downloadOptions) : Promise<Stream>;
/**
* Gets the information of a playlist including the video's inside the playlist
* @param url The url of the playlist
*/
export declare function getPlaylist(url: string) : Promise<Playlist>;
/**
* Adds custom headers to each request made to YouTube
* @param headers The headers you'd like to add in each request
*/
export declare function setGlobalHeaders(headers: object) : void;
/**
* Sets a custom agent which is being used to send the requests with
* @param agent An instance of the YTStreamAgent class which represents the HTTP agent
*/
export declare function setGlobalAgent(agent: YTStreamAgent | {https: HttpsAgent | HttpsCookieAgent | any, http: HttpAgent | HttpCookieAgent | any} | any) : void;
/**
* Allows you to set an api key which can be used to get information instead of scraping pages
* @param apiKey Your api key to use
*/
export declare function setApiKey(apiKey: string) : void;
/**
* Allows you to choose whether to use the api or scraping methods to get information
* @param preference The method you prefer
*/
export declare function setPreference(preference: 'scrape' | 'api', client?: 'IOS' | 'ANDROID') : void;
declare var cookie: string;
declare var userAgent: string;
export declare class Cookie extends ToughCookie{}
export declare class YTStreamAgent{
constructor(cookies: CookieType, options: HttpsCookieAgentOptions | HttpCookieAgentOptions);
/**
* Adds cookies to the cookies headers which is being send in each request to YouTube
* @param cookies An array or an instance of the Cookie class which represents the cookie you want to add
*/
addCookies(cookies: [] | ToughCookie) : void;
/**
* Removes the cookies which the agent has saved
* @param force True to remove manually set cookies as well, false to only remove cached cookies (default false)
*/
removeCookies(force?: boolean) : void;
/**
* Import cookies from a json file and sync them with the cookies YouTube provides so they stay up-to-date
* @param filePath The path to the file of the cookies (absolute or from the cwd)
*/
syncFile(filePath: string) : void;
}