-
Notifications
You must be signed in to change notification settings - Fork 1
/
ref.js
604 lines (546 loc) · 15.6 KB
/
ref.js
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
//Reference Scriptfile
//Intended exclusively for auto-complete in your IDE, not for execution
var IS_TESTING = false;
let Type = {
Source: {
Dash: "DASH",
HLS: "HLS",
STATIC: "Static"
},
Feed: {
Videos: "VIDEOS",
Streams: "STREAMS",
Mixed: "MIXED",
Live: "LIVE"
},
Order: {
Chronological: "CHRONOLOGICAL"
},
Date: {
LastHour: "LAST_HOUR",
Today: "TODAY",
LastWeek: "LAST_WEEK",
LastMonth: "LAST_MONTH",
LastYear: "LAST_YEAR"
},
Duration: {
Short: "SHORT",
Medium: "MEDIUM",
Long: "LONG"
}
};
let Language = {
UNKNOWN: "Unknown",
ARABIC: "Arabic",
SPANISH: "Spanish",
FRENCH: "French",
HINDI: "Hindi",
INDONESIAN: "Indonesian",
KOREAN: "Korean",
PORTBRAZIL: "Portuguese Brazilian",
RUSSIAN: "Russian",
THAI: "Thai",
TURKISH: "Turkish",
VIETNAMESE: "Vietnamese",
ENGLISH: "English"
}
class ScriptException extends Error {
constructor(type, msg) {
if(arguments.length == 1) {
super(arguments[0]);
this.plugin_type = "ScriptException";
this.message = arguments[0];
}
else {
super(msg);
this.plugin_type = type ?? ""; //string
this.msg = msg ?? ""; //string
}
}
}
class UnavailableException extends ScriptException {
constructor(msg) {
super("UnavailableException", msg);
}
}
class AgeException extends ScriptException {
constructor(msg) {
super("AgeException", msg);
}
}
class TimeoutException extends ScriptException {
constructor(msg) {
super(msg);
this.plugin_type = "ScriptTimeoutException";
}
}
class Thumbnails {
constructor(thumbnails) {
this.sources = thumbnails ?? []; // Thumbnail[]
}
}
class Thumbnail {
constructor(url, quality) {
this.url = url ?? ""; //string
this.quality = quality ?? 0; //integer
}
}
class PlatformID {
constructor(platform, id, pluginId) {
this.platform = platform ?? ""; //string
this.pluginId = pluginId; //string
this.value = id; //string
}
}
class ResultCapabilities {
constructor(types, sorts, filters) {
this.types = types ?? [];
this.sorts = sorts ?? [];
this.filters = filters ?? [];
}
}
class FilterGroup {
constructor(name, filters, isMultiSelect, id) {
if(!name) throw new ScriptException("No name for filter group");
if(!filters) throw new ScriptException("No filter provided");
this.name = name
this.filters = filters
this.isMultiSelect = isMultiSelect;
this.id = id;
}
}
class FilterCapability {
constructor(name, value, id) {
if(!name) throw new ScriptException("No name for filter");
if(!value) throw new ScriptException("No filter value");
this.name = name;
this.value = value;
this.id = id;
}
}
class PlatformAuthorLink {
constructor(id, name, url, thumbnail, subscribers) {
this.id = id ?? PlatformID(); //PlatformID
this.name = name ?? ""; //string
this.url = url ?? ""; //string
this.thumbnail = thumbnail; //string
if(subscribers)
this.subscribers = subscribers;
}
}
class Content {
constructor(type) {
this.contentType = type;
}
}
class ContentDetails {
constructor(type) {
this.contentType = type;
}
}
class PlatformVideo extends Content {
constructor(obj) {
super(1);
obj = obj ?? {};
this.plugin_type = "PlatformVideo";
this.id = obj.id ?? PlatformID(); //PlatformID
this.name = obj.name ?? ""; //string
this.thumbnails = obj.thumbnails; //Thumbnail[]
this.author = obj.author; //PlatformAuthorLink
this.datetime = obj.datetime ?? obj.uploadDate ?? 0; //OffsetDateTime (Long)
this.url = obj.url ?? ""; //String
this.duration = obj.duration ?? -1; //Long
this.viewCount = obj.viewCount ?? -1; //Long
this.isLive = obj.isLive ?? false; //Boolean
}
}
class PlatformVideoDetails extends PlatformVideo {
constructor(obj) {
super(obj);
obj = obj ?? {};
this.plugin_type = "PlatformVideoDetails";
this.description = obj.description ?? "";//String
this.video = obj.video ?? {}; //VideoSourceDescriptor
this.dash = obj.dash ?? null; //DashSource
this.hls = obj.hls ?? null; //HLSSource
this.live = obj.live ?? null; //VideoSource
this.rating = obj.rating ?? null; //IRating
this.subtitles = obj.subtitles ?? [];
}
}
//Sources
class VideoSourceDescriptor {
constructor(obj) {
obj = obj ?? {};
this.plugin_type = "MuxVideoSourceDescriptor";
this.isUnMuxed = false;
if(obj.constructor === Array)
this.videoSources = obj;
else
this.videoSources = obj.videoSources ?? [];
}
}
class UnMuxVideoSourceDescriptor {
constructor(videoSourcesOrObj, audioSources) {
videoSourcesOrObj = videoSourcesOrObj ?? {};
this.plugin_type = "UnMuxVideoSourceDescriptor";
this.isUnMuxed = true;
if(videoSourcesOrObj.constructor === Array) {
this.videoSources = videoSourcesOrObj;
this.audioSources = audioSources;
}
else {
this.videoSources = videoSourcesOrObj.videoSources ?? [];
this.audioSources = videoSourcesOrObj.audioSources ?? [];
}
}
}
class VideoUrlSource {
constructor(obj) {
obj = obj ?? {};
this.plugin_type = "VideoUrlSource";
this.width = obj.width ?? 0;
this.height = obj.height ?? 0;
this.container = obj.container ?? "";
this.codec = obj.codec ?? "";
this.name = obj.name ?? "";
this.bitrate = obj.bitrate ?? 0;
this.duration = obj.duration ?? 0;
this.url = obj.url;
}
}
class YTVideoSource extends VideoUrlSource {
constructor(obj) {
super(obj);
this.plugin_type = "VideoYTSource";
this.itagId = obj.itagId ?? null;
this.initStart = obj.initStart ?? null;
this.initEnd = obj.initEnd ?? null;
this.indexStart = obj.indexStart ?? null;
this.indexEnd = obj.indexEnd ?? null;
}
}
class AudioUrlSource {
constructor(obj) {
obj = obj ?? {};
this.plugin_type = "AudioUrlSource";
this.name = obj.name ?? "";
this.bitrate = obj.bitrate ?? 0;
this.container = obj.container ?? "";
this.codec = obj.codec ?? "";
this.duration = obj.duration ?? 0;
this.url = obj.url;
this.language = obj.language ?? Language.UNKNOWN;
}
}
class YTAudioSource extends AudioUrlSource {
constructor(obj) {
super(obj);
this.plugin_type = "AudioYTSource";
this.itagId = obj.itagId ?? null;
this.initStart = obj.initStart ?? null;
this.initEnd = obj.initEnd ?? null;
this.indexStart = obj.indexStart ?? null;
this.indexEnd = obj.indexEnd ?? null;
this.audioChannels = obj.audioChannels ?? 2;
}
}
class HLSSource {
constructor(obj) {
obj = obj ?? {};
this.plugin_type = "HLSSource";
this.name = obj.name ?? "HLS";
this.duration = obj.duration ?? 0;
this.url = obj.url;
}
}
class DashSource {
constructor(obj) {
obj = obj ?? {};
this.plugin_type = "DashSource";
this.name = obj.name ?? "Dash";
this.duration = obj.duration ?? 0;
this.url = obj.url;
}
}
//Channel
class PlatformChannel {
constructor(obj) {
obj = obj ?? {};
this.plugin_type = "PlatformChannel";
this.id = obj.id ?? ""; //string
this.name = obj.name ?? ""; //string
this.thumbnail = obj.thumbnail; //string
this.banner = obj.banner; //string
this.subscribers = obj.subscribers ?? 0; //integer
this.description = obj.description; //string
this.url = obj.url ?? ""; //string
this.links = obj.links ?? { } //Map<string,string>
}
}
//Playlist
class PlatformPlaylist {
constructor(obj) {
obj = obj ?? {};
this.plugin_type = "PlatformPlaylist";
this.id = obj.id ?? null;
this.url = obj.url;
this.name = obj.name ?? "";
this.videoCount = obj.videoCount ?? 0;
this.thumbnail = obj.thumbnail;
}
}
class PlatformPlaylistDetails extends PlatformPlaylist {
constructor(obj) {
super(obj);
this.plugin_type = "PlatformPlaylistDetails";
this.contents = obj.contents;
}
}
//Ratings
class RatingLikes {
constructor(likes) {
this.type = 1;
this.likes = likes;
}
}
class RatingLikesDislikes {
constructor(likes,dislikes) {
this.type = 2;
this.likes = likes;
this.dislikes = dislikes;
}
}
class RatingScaler {
constructor(value) {
this.type = 3;
this.value = value;
}
}
class Comment {
constructor(obj) {
this.plugin_type = "Comment";
this.contextUrl = obj.contextUrl ?? "";
this.author = obj.author ?? new PlatformAuthorLink(null, "", "", null);
this.message = obj.message ?? "";
this.rating = obj.rating ?? new RatingLikes(0);
this.date = obj.date ?? 0;
this.replyCount = obj.replyCount ?? 0;
this.context = obj.context ?? {};
}
}
class LiveEventPager {
constructor(results, hasMore, context) {
this.plugin_type = "LiveEventPager";
this.results = results ?? [];
this.hasMore = hasMore ?? false;
this.context = context ?? {};
this.nextRequest = 4000;
}
hasMorePagers() { return this.hasMore; }
nextPage() { return new Pager([], false, this.context) }
}
class LiveEvent {
constructor(type) {
this.type = type;
}
}
class LiveEventComment extends LiveEvent {
constructor(name, message, thumbnail) {
super(1);
this.name = name;
this.message = message;
this.thumbnail = thumbnail;
}
}
class LiveEventEmojis extends LiveEvent {
constructor(emojis) {
super(4);
this.emojis = emojis;
}
}
class LiveEventDonation extends LiveEvent {
constructor(amount, name, message, thumbnail) {
super(5);
this.amount = amount;
this.name = name;
this.message = message ?? "";
this.thumbnail = thumbnail;
}
}
class LiveEventViewCount extends LiveEvent {
constructor(viewCount) {
super(10);
this.viewCount = viewCount;
}
}
class LiveEventRaid extends LiveEvent {
constructor(targetUrl, targetName, targetThumbnail) {
super(100);
this.targetUrl = targetUrl;
this.targetName = targetName;
this.targetThumbnail = targetThumbnail;
}
}
//Pagers
class ContentPager {
constructor(results, hasMore, context) {
this.plugin_type = "ContentPager";
this.results = results ?? [];
this.hasMore = hasMore ?? false;
this.context = context ?? {};
}
hasMorePagers() { return this.hasMore; }
nextPage() { return new ContentPager([], false, this.context) }
}
class VideoPager {
constructor(results, hasMore, context) {
this.plugin_type = "VideoPager";
this.results = results ?? [];
this.hasMore = hasMore ?? false;
this.context = context ?? {};
}
hasMorePagers() { return this.hasMore; }
nextPage() { return new VideoPager([], false, this.context) }
}
class ChannelPager {
constructor(results, hasMore, context) {
this.plugin_type = "ChannelPager";
this.results = results ?? [];
this.hasMore = hasMore ?? false;
this.context = context ?? {};
}
hasMorePagers() { return this.hasMore; }
nextPage() { return new Pager([], false, this.context) }
}
class PlaylistPager {
constructor(results, hasMore, context) {
this.plugin_type = "PlaylistPager";
this.results = results ?? [];
this.hasMore = hasMore ?? false;
this.context = context ?? {};
}
hasMorePagers() { return this.hasMore; }
nextPage() { return new Pager([], false, this.context) }
}
class CommentPager {
constructor(results, hasMore, context) {
this.plugin_type = "CommentPager";
this.results = results ?? [];
this.hasMore = hasMore ?? false;
this.context = context ?? {};
}
hasMorePagers() { return this.hasMore; }
nextPage() { return new Pager([], false, this.context) }
}
function throwException(type, message) {
throw new Error("V8EXCEPTION:" + type + "-" + message);
}
//To override by plugin
const source = {
getHome() { return new ContentPager([], false, {}); },
enable(config){ },
disable() {},
searchSuggestions(query){ return []; },
getSearchCapabilities(){ return { types: [], sorts: [] }; },
search(query, type, order, filters){ return new ContentPager([], false, {}); }, //TODO
//OPTIONAL getSearchChannelContentsCapabilities(){ return { types: [], sorts: [] }; },
//OPTIONAL searchChannelContents(channelUrl, query, type, order, filters){ return new Pager([], false, {}); }, //TODO
isChannelUrl(url){ return false; },
getChannel(url){ return null; },
getChannelCapabilities(){ return { types: [], sorts: [] }; },
getChannelContents(url, type, order, filters) { return new ContentPager([], false, {}); },
isContentDetailsUrl(url){ return false; },
getContentDetails(url){ }, //TODO
//OPTIONAL getComments(url){ return new Pager([], false, {}); }, //TODO
//OPTIONAL getSubComments(comment){ return new Pager([], false, {}); }, //TODO
//OPTIONAL getSubscriptionsUser(){ return []; },
//OPTIONAL getPlaylistsUser(){ return []; }
};
function parseSettings(settings) {
if(!settings)
return {};
let newSettings = {};
for(let key in settings) {
if(typeof settings[key] == "string")
newSettings[key] = JSON.parse(settings[key]);
else
newSettings[key] = settings[key];
}
return newSettings;
}
function log(str) {
if(str) {
if(typeof str == "string")
bridge.log(str);
else
bridge.log(JSON.stringify(str, null, 4));
}
}
//Package Bridge (variable: bridge)
let bridge = {
/**
* @return {Boolean}
**/
isLoggedIn: function() {},
/**
* @param {String} str
* @return {Unit}
**/
log: function(str) {},
/**
* @param {String} str
* @return {Unit}
**/
throwTest: function(str) {},
/**
* @param {String} str
* @return {Unit}
**/
toast: function(str) {},
}
//Package Http (variable: http)
let http = {
/**
* @param {String} url
* @param {Map} headers
* @param {Boolean} useAuth
* @return {BridgeHttpResponse}
**/
GET: function(url, headers, useAuth) {},
/**
* @param {String} url
* @param {String} body
* @param {Map} headers
* @param {Boolean} useAuth
* @return {BridgeHttpResponse}
**/
POST: function(url, body, headers, useAuth) {},
/**
* @return {BatchBuilder}
**/
batch: function() {},
/**
* @param {String} method
* @param {String} url
* @param {Map} headers
* @param {Boolean} useAuth
* @return {BridgeHttpResponse}
**/
request: function(method, url, headers, useAuth) {},
/**
* @param {String} method
* @param {String} url
* @param {String} body
* @param {Map} headers
* @param {Boolean} useAuth
* @return {BridgeHttpResponse}
**/
requestWithBody: function(method, url, body, headers, useAuth) {},
/**
* @param {V8ValueObject} socketObj
* @param {Boolean} useAuth
* @return {SocketResponse}
**/
socket: function(socketObj, useAuth) {},
}