-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
254 lines (228 loc) · 6.98 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
import { Readable } from "stream";
import { EventEmitter } from "events";
import { Cookie as ToughCookie } from "tough-cookie";
import { HttpsCookieAgent, HttpCookieAgent } from "http-cookie-agent/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;
per_sec_bytes: number;
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;
}
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;
}];
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
*/
export declare function getInfo(url: string) : 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) : 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;
}