-
Notifications
You must be signed in to change notification settings - Fork 91
/
iTS Upload Helper.js
3733 lines (3619 loc) · 135 KB
/
iTS Upload Helper.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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name iTS Upload Helper
// @namespace http://tampermonkey.net/
// @version 1.33
// @description Upload Helper for iTS
// @author Shix
// @match https://shadowthein.net/upload.php*
// @match http://shadowthein.net/upload.php*
// @require https://gist.github.com/po5/3fc587478a6b2cdb32e403e8a1b0198b/raw/mediainfo.js
// @icon https://shadowthein.net/favicon.ico
// @connect omdbapi.com
// @connect themoviedb.org
// @connect ptpimg.me
// @connect imgbb.com
// @connect imdb.com
// @connect rottentomatoes.com
// @connect metacritic.com
// @connect criterion.com
// @connect eurekavideo.co.uk
// @grant GM.xmlHttpRequest
// @grant GM.getValue
// @grant GM.setValue
// @grant GM_getResourceText
// @grant GM_addStyle
// ==/UserScript==
// ------------------------------------------------------ User Editable Fields --------------------------------------------------
// OPTIONAL: You can enter your api keys here.
var TMDB_API_KEY = "";
var OMDB_API_KEY = "";
var IMGBB_API_KEY = "";
var PTPIMG_API_KEY = "";
// values can be "final" or "f" for the final template. "compact" or "c" for the compact template or "" for normal
var TEMPLATE_VERSION = "f";
// ------------------------------------------------------ End of User Editable Fields --------------------------------------------------
// ------------------------------------------------------ Do Not Edit Below (Unless you know what you are doing) --------------------------------------------------
// MediaInfo File Parser Variables
var CHUNK_SIZE = 5 * 1024 * 1024;
var miLib, mi;
var processing = false;
miLib = MediaInfo(function () {
mi = new miLib.MediaInfo();
});
var media = new MediaDetails();
let Utilities = {
imgbb_key: IMGBB_API_KEY || "48e419e43be3bffe7504554dbe7f604e",
ptpimg_key: PTPIMG_API_KEY || "",
capitalize: function (text) {
return text.replace(/(?:^|\s)\S/g, function (a) {
return a.toUpperCase();
});
},
/**
* Fetches a json object from a url
*
* @param {string} url A Url that returns a Json
* @param {object} options fetch options
* @return {Promise} A Json object
*/
fetchJson: async (url, options = {}) => {
const resp = await fetch(url, options);
if (!resp.ok) {
throw Error(
`Error: Fetching data from ${url} resulted in ${resp.status} - ${resp.statusText}`
);
}
const data = await resp.json();
return data;
},
simpleRExtractor: {
extractReleaseGroup: (name) => {
try {
const reTrimEnd = /[.\-\s]$/gi;
const reGroup = /.*-(?<release_group>[^\-.]*)$/gi;
const {
groups: { release_group },
} = reGroup.exec(name.replace(reTrimEnd, ""));
return release_group || "";
} catch (error) {
return "";
}
},
extractResolution: (name) => {
try {
const reRes = /[._\-\s](?<res>(?:\d{3,4}[pi])|(?:pal|ntsc))[._\-\s]/gi;
const {
groups: { res },
} = reRes.exec(name);
return res || "";
} catch (error) {
return "";
}
},
extractCriterion: (name) => {
const reCriterion = /[._\-\s](criterion)[._\-\s]/gi;
return reCriterion.test(name) ? "Criterion" : "";
},
extractRemux: (name) => {
const reRemux = /[._\-\s](remux)[._\-\s]/gi;
return reRemux.test(name) ? "Remux" : "";
},
extractSeason: (name) => {
try {
const reSeason = /[._\-\s](?<season>[se]\d{1,3}){1,2}[._\-\s]/gi;
const {
groups: { season },
} = reSeason.exec(name);
return season || "";
} catch (error) {
return "";
}
},
extractEpisode: (name) => {
try {
const reEpisode = /[._\-\s](?:s\d{1,3})?(?<episode>e\d{1,3})[._\-\s]/gi;
const {
groups: { episode },
} = reEpisode.exec(name);
return episode || "";
} catch (error) {
return "";
}
},
},
/**
* Returns an Object with info about the Image uploaded to Imgbb
*
* @param {string} imgUrl Image URL you want to upload
* @return {{id: string,
* extension: string,
* mime: string,
* name: string,
* size: string,
* time: string,
* thumbnail_url: string,
* url: string}}
*/
createimgbbImage: async function (imgUrl) {
const apiKey = Utilities.imgbb_key || "";
let url = `https://api.imgbb.com/1/upload?key=${apiKey}`;
let form = new FormData();
if (typeof imgUrl === "string" && imgUrl.startsWith("data:")) {
imgUrl = imgUrl.split(",", 2)[1];
}
form.append("image", imgUrl);
let options = {
body: form,
method: "POST",
timeout: 5000,
processData: false,
mimeType: "multipart/form-data",
contentType: false,
};
// let fill = (data) => {
// this.id = data.id;
// this.extension = data.image.extension;
// this.mime = data.image.mime;
// this.name = data.title;
// this.size = data.size;
// this.time = data.time;
// this.thumbnail_url = data.thumb.url;
// this.url = data.image.url
// };
let upload = async (imgUrl) => {
let response = await Utilities.fetchJson(url, options)
.then((r) => r.data)
.catch((err) => console.log(err));
// fill(response);
return response;
};
let data = await upload(imgUrl);
// console.log(data);
if (typeof data === "undefined") return;
return {
id: data.id,
extension: data.image.extension,
mime: data.image.mime,
name: data.title,
size: data.size,
time: data.time,
thumbnail_url: data.thumb.url,
url: data.image.url,
};
},
createPtpImg: async function (imgUrl) {
const apiKey = Utilities.ptpimg_key || "";
let url = `https://ptpimg.me/upload.php`;
let ptpHeaders = new Headers();
ptpHeaders.append("Referer", "https://ptpimg.me/index.php");
let form = new FormData();
let imgKey = imgUrl instanceof File ? "file-upload" : "link-upload";
if (typeof imgUrl === "string" && imgUrl.startsWith("data:")) {
imgUrl = imgUrl.split(",", 2)[1];
}
let formdata = {
api_key: apiKey,
};
formdata[imgKey] = imgUrl;
// console.log(formdata);
let resp = await Utilities.xhrQuery(url, "", "post", {}, formdata).then((r) =>
JSON.parse(r.response)
);
return {
id: resp[0].code,
extension: resp[0].ext,
url: `https://ptpimg.me/${resp[0].code}.${resp[0].ext}`,
};
},
createImage: async function (imgUrl) {
if (Utilities.ptpimg_key) {
return await Utilities.createPtpImg(imgUrl);
} else if (Utilities.imgbb_key) {
return await Utilities.createimgbbImage(imgUrl);
}
},
xhrQuery: function (baseUrl, path, method = "get", params = {}, data = {}) {
let resolver;
let rejecter;
const p = new Promise((resolveFn, rejectFn) => {
resolver = resolveFn;
rejecter = rejectFn;
});
const formData = new FormData();
for (const [key, value] of Object.entries(data)) {
formData.append(key, value);
}
const paramStr = new URLSearchParams(params).toString();
const obj = {
method,
timeout: 30000,
onloadstart: () => {},
onload: (result) => {
if (result.status !== 200) {
console.log("XHR Errored Result", result);
rejecter(new Error("XHR failed"));
return;
}
resolver(result);
},
onerror: (result) => {
rejecter(result);
},
ontimeout: (result) => {
rejecter(result);
},
};
const final =
method === "post"
? Object.assign({}, obj, {
url: `${baseUrl}${path}${paramStr.length > 0 ? `?${paramStr}` : ""}`,
data: formData,
})
: Object.assign({}, obj, {
url: `${baseUrl}${path}${paramStr.length > 0 ? `?${paramStr}` : ""}`,
});
GM.xmlHttpRequest(final);
return p;
},
parseHtmlString: function (htmlString, query, hasMultipleResults = false) {
const parser = new DOMParser();
const doc = parser.parseFromString(htmlString, "text/html");
// const element = doc.querySelector(query);
// return element;
if (hasMultipleResults) {
return doc.querySelectorAll(query);
}
return doc.querySelector(query);
},
htmlToElement: function (html) {
let template = document.createElement('template');
template.innerHTML = html.trim();
return template.content;
},
};
let BBCode = {
Center: function (content) {
return `[center]${content}[/center]`;
},
Hr: function () {
return `[hr]`;
},
Bold: function (content) {
if(!content) return "";
return `[b]${content}[/b]`;
},
Italic: function (content) {
return `[i]${content}[/i]`;
},
Underline: function (content) {
return `[u]${content}[/u]`;
},
Strikethrough: function (content) {
return `[s]${content}[/s]`;
},
Box: function (title, content) {
return `[box${title ? "="+title : ""}]${content}[/box]`;
},
Size: function (size, content) {
if (size < 1 || size > 7) return "";
return `[size=${size}]${content}[/size]`;
},
Font: function (font, content) {
return `[font=${font}]${content}[/font]`;
},
Color: function (color, content) {
return `[color=${color}]${content}[/color]`;
},
Hide: function (content) {
return `[hide]${content}[/hide]`;
},
Spoiler: function (content) {
return `[spoiler]${content}[/spoiler]`;
},
Preformat: function (content) {
return `[pre]${content}[/pre]`;
},
Img: function (imgUrl) {
return `[img]${imgUrl}[/img]`;
},
Url: function (url, content) {
return `[url=${url}]${content}[/url]`;
},
Quote: function (name, content) {
return `[quote=${name}]${content}[/quote]`;
},
Youtube: function (ytUrl) {
return `[youtube]${ytUrl}[/youtube]`;
},
Vimeo: function (vimUrl) {
return `[vimeo]${vimUrl}[/vimeo]`;
},
List: function (items) {
if (!Array.isArray(items)) return `[*] ${items}`;
return items.map((i) => `[*] ${i}`).join("\n");
},
};
let tmdb = {
config: {
api_key: TMDB_API_KEY || "843bcb3112cd960e28931bdf5e9e0329",
url: "https://api.themoviedb.org/3/",
image_url: "https://image.tmdb.org/t/p/original/",
language: "en-US",
timeout: 5000,
},
common: {
find: async (id, source = "imdb") => {
// external_source string Allowed Values: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id, facebook_id, twitter_id, instagram_id
source = source.endsWith("_id") ? source : source + "_id";
let options = {
external_source: source,
};
let url = tmdb.common.generateUrl("find", id, options);
return await Utilities.fetchJson(url);
},
/**
* Gets the TMDB ID and type of content using other IDs
*
* @param {string} id IMDB ID
* @param {string} source Source of the ID you are using
* @returns {{tmdb_id: string, type: string}}
*/
getTmdbIdAndType: async (id, source) => {
let output = {
tmdb_id: "",
media_type: "",
};
let { movie_results, tv_results } = await tmdb.common.find(id, source);
if ((await movie_results.length) > 0) {
output.tmdb_id = movie_results[0].id.toString();
output.media_type = "movie";
} else if ((await tv_results.length) > 0) {
output.tmdb_id = tv_results[0].id.toString();
output.media_type = "tv";
}
return output;
},
generateUrl: (endpoint, id, options) => {
return `${tmdb.config.url}${endpoint}/${id}${tmdb.common.generateQuery(options)}`;
},
generateQuery: (options) => {
"use strict";
let myOptions, query, option;
myOptions = options || {};
query = "?api_key=" + tmdb.config.api_key + "&language=" + tmdb.config.language;
if (Object.keys(myOptions).length > 0) {
for (option in myOptions) {
if (myOptions.hasOwnProperty(option) && option !== "id" && option !== "body") {
query = query + "&" + option + "=" + myOptions[option];
}
}
}
return query;
},
},
movie: {
getDetails: async (id, options) => {
options = options || {
append_to_response: "external_ids,credits,images,videos",
include_image_language: "en,null",
};
let url = tmdb.common.generateUrl("movie", id, options);
let result = {};
try {
result = await Utilities.fetchJson(url);
} catch (err) {
console.log("TMDB GetDetails", err);
}
return result;
},
},
tv: {
getDetails: async (id, options) => {
options = options || {
append_to_response: "external_ids,credits,images,videos",
include_image_language: "en,null",
};
let url = tmdb.common.generateUrl("tv", id, options);
let result = {};
try {
result = await Utilities.fetchJson(url);
} catch (err) {
console.log("TMDB GetDetails", err);
}
return result;
},
},
getDetails: async (id, media_type, options) => {
options = options || {
append_to_response: "external_ids,credits,images,videos",
include_image_language: "en,null",
};
let url = tmdb.common.generateUrl(media_type, id, options);
let result = {};
console.log(url);
try {
result = await Utilities.fetchJson(url);
} catch (err) {
console.log("TMDB GetDetails", err);
}
// console.log(result)
return result;
},
};
function getOmdbKey() {
let keys = ["314cc4be", "2c5e0ae7", "3d37ff4d"];
return keys[Math.floor(Math.random() * keys.length)];
}
let omdb = {
config: {
url: "https://www.omdbapi.com/",
api_key: OMDB_API_KEY || getOmdbKey(),
},
getDetails: async (id) => {
// console.log(omdb.config.api_key)
const finalUrl = `${omdb.config.url}?apikey=${omdb.config.api_key}&i=${id}&plot=full&y&tomatoes=true&r=json`;
return await Utilities.fetchJson(finalUrl);
},
};
function MediaDetails() {
const imdbUrl = "https://www.imdb.com/title/";
const tmdbUrl = "https://www.themoviedb.org/";
const tmdbImageUrl = "https://image.tmdb.org/t/p/original/";
const youtubeUrl = "https://www.youtube.com/watch?v=";
const vimeoUrl = "https://vimeo.com/";
const infoTemplate = {
imdb_id: "",
tmdb_id: "",
title: "",
year: "",
created_by: [],
directors: [],
in_production: false,
genres: [],
networks: [],
overview: "",
criterion_overview: "",
original_title: "",
original_language: "",
origin_country: "",
backdrop_url: "",
poster_url: "",
criterion_poster_url: "",
criterion_spine: "",
criterion_box_sets: [],
moc_overview: "",
moc_poster_url: "",
moc_spine: "",
moc_url: "",
producers: "",
production_companies: [],
production_countries: [],
rated: "",
release_date: "",
runtime: "",
spoken_languages: [],
status: "",
imdb_rating: "",
tmdb_rating: "",
metacritic_rating: "",
rt_rating: "",
site_urls: {
imdb: "",
tmdb: "",
metacritic: "",
rotten_tomatoes: "",
criterion: "",
},
ratings: {
imdb: "",
tmdb: "",
metacritic: "",
rotten_tomatoes: "",
criterion: "",
moc: "",
},
tagline: "",
trailer_url: "",
type: "",
seasons: [],
writers: [],
input_source: "",
media_type: "",
};
const torrentInfoTemplate = {
name: "",
resolution: "",
season: "",
criterion: "",
remux: "",
release_group: "",
media_type: "",
};
let details = false;
this.info = {};
this.torrentInfo = {};
this.mediaInfo = {};
this.screenshots = [];
this.success = false;
this.init = async function ({
url = "",
torrentName = "",
mediaInfo = "",
screenshots = "",
criterion = "",
mocUrl = "",
}) {
if (url) {
await this.initURL(url);
}
if (torrentName) {
this.initTorrentName(torrentName);
}
if (mediaInfo && /General[\S\s]*Video[\S\s]*Audio/gi.test(mediaInfo)) {
this.initMediaInfo(mediaInfo);
}
if (screenshots) {
this.initScreenshots(screenshots);
}
if (criterion) {
await this.initCriterion(criterion);
} else {
clearCriterionInfo();
}
if (mocUrl) {
await this.initMoc(mocUrl);
} else {
clearMocInfo();
}
};
this.initURL = async function (url) {
// debugger;
if (!url) {
return;
}
const urlInfo = extractUrlInfo(url);
if (
Object.keys(this.info).length > 0 &&
((urlInfo.imdb_id && urlInfo.imdb_id !== this.info.imdb_id) ||
(urlInfo.tmdb_id && urlInfo.tmdb_id !== this.info.tmdb_id))
) {
details = false;
this.info = {};
}
if (
(Object.keys(this.info).length > Object.keys(urlInfo).length &&
urlInfo.imdb_id &&
urlInfo.imdb_id === this.info.imdb_id) ||
(urlInfo.tmdb_id && urlInfo.tmdb_id === this.info.tmdb_id)
) {
return;
}
if (!details) {
details = true;
details = this.initURL(url);
} else if (typeof details.then === "function") {
await details;
details = false;
return;
}
setInfo(urlInfo);
if (typeof tmdb != "undefined" && tmdb.config.api_key) {
if (this.info.tmdb_id && this.info.media_type) {
fillTmdbInfo(await tmdb.getDetails(this.info.tmdb_id, this.info.media_type));
} else if (this.info.imdb_id && this.info.media_type === "movie") {
fillTmdbInfo(await tmdb.movie.getDetails(this.info.imdb_id));
} else if (this.info.imdb_id) {
setInfo(await tmdb.common.getTmdbIdAndType(this.info.imdb_id, this.info.input_source));
fillTmdbInfo(await tmdb.getDetails(this.info.tmdb_id, this.info.media_type));
} else {
throw Error("Url or Id Provided is Invalid");
}
} else {
throw Error("TMDB Error");
}
if (typeof omdb != "undefined" && omdb.config.api_key) {
if (this.info.imdb_id) {
fillOmdbInfo(await omdb.getDetails(this.info.imdb_id));
}
}
if (!this.success) return;
await fillSiteUrls();
};
this.initTorrentName = function (torrentName) {
if (!torrentName) return;
this.torrentInfo = extractTorrentNameInfo(torrentName);
};
this.initMediaInfo = function (text) {
if (!text) return;
this.mediaInfo = parseMediaInfoTextToJson(text);
this.mediaInfo.General["Complete Name"] = this.mediaInfo.General["Complete Name"]
.trim()
.split("\\")
.pop()
.split("/")
.pop();
};
this.initScreenshots = function (screenshots) {
if (Array.isArray(screenshots)) {
this.screenshots = screenshots;
}
if (typeof screenshots === "string") {
this.screenshots = screenshots.split("\n");
}
};
this.initCriterion = async function (criterion) {
if (!criterion || /.*criterion.com\/films\/\d+.*/gi.test(criterion) === false) {
clearCriterionInfo();
return;
}
if (!Object.keys(this.info).includes("site_urls")) {
this.info.site_urls = {};
}
if (!Object.keys(this.info).includes("ratings")) {
this.info.ratings = {};
}
if (
Object.keys(this.info.site_urls).includes("criterion") &&
this.info.site_urls.criterion === criterion
) {
return;
}
clearCriterionInfo();
this.info.site_urls.criterion = criterion;
await fillCriterionInfo(criterion);
};
this.initMoc = async function (mocUrl) {
if (!mocUrl || /.*eurekavideo.co.uk\/movie\/.*/gi.test(mocUrl) === false) {
clearMocInfo();
return;
}
if (!Object.keys(this.info).includes("site_urls")) {
this.info.site_urls = {};
}
if (!Object.keys(this.info).includes("ratings")) {
this.info.ratings = {};
}
if (
Object.keys(this.info.site_urls).includes("moc") &&
this.info.site_urls.moc === mocUrl
) {
return;
}
clearMocInfo();
this.info.site_urls.moc = mocUrl;
await fillMocInfo(mocUrl);
};
this.getImdbUrl = function () {
if (typeof this.info.site_urls !== "undefined" && this.info.site_urls.imdb) {
return this.info.site_urls.imdb;
}
return (checkKeyInInfo("imdb_id") && imdbUrl + this.info.imdb_id) || "";
};
this.getTmdbUrl = function () {
if (typeof this.info.site_urls !== "undefined" && this.info.site_urls.tmdb) {
return this.info.site_urls.tmdb;
}
return (checkKeyInInfo("tmdb_id") && tmdbUrl + this.info.media_type + "/" + this.info.tmdb_id) || "";
};
this.isDocumentary = function () {
return this.info.genres?.some((g) => g.id === 99);
};
this.hasCriterionBoxSet = function () {
return this.info.criterion_box_sets?.length > 0;
};
this.getCriterionBoxSetSpine = function () {
return this.hasCriterionBoxSet
? this.info.criterion_box_sets.filter((set) => set.spine)[0]?.spine || ""
: "";
};
this.isCriterion = function () {
return Boolean(checkKeyInInfo("site_urls") && this.info.site_urls.criterion);
};
this.getCriterionUrl = function () {
return this.isCriterion() ? this.info.site_urls.criterion : "";
};
this.hasCriterionSpine = function () {
return this.info.criterion_spine;
};
this.getCriterionSpine = function () {
return this.isCriterion() ? this.info.criterion_spine : "";
};
this.isMoC = function () {
return Boolean(checkKeyInInfo("site_urls") && this.info.site_urls.moc);
};
this.getMocUrl = function () {
return this.isMoC() ? this.info.site_urls.moc : "";
};
this.hasMocSpine = function () {
return this.info.moc_spine;
};
this.getMocSpine = function () {
return this.isMoC ? this.info.moc_spine : "";
};
this.getYoutubeTrailerId = function () {
if (checkKeyInInfo("trailer_url") && this.info.trailer_url.site.toLowerCase() === "youtube"){
return this.info.trailer_url.key || "";
}
return ""
};
this.getYoutubeTrailerUrl = function () {
if (checkKeyInInfo("trailer_url") && this.info.trailer_url.site.toLowerCase() === "youtube"){
return youtubeUrl + this.getYoutubeTrailerId() || "";
}
return "";
};
this.getVimeoTrailerId = function () {
if (checkKeyInInfo("trailer_url") && this.info.trailer_url.site.toLowerCase() === "vimeo"){
return this.info.trailer_url.key || "";
}
return ""
};
this.getVimeoTrailerUrl = function () {
if (checkKeyInInfo("trailer_url") && this.info.trailer_url.site.toLowerCase() === "vimeo"){
return vimeoUrl + this.getYoutubeTrailerId() || "";
}
return "";
};
this.getDirectorNames = function () {
// if(checkKeyInInfo("directors") && typeof this.info.directors === "string"){
// return this.info.directors.split(", ");
// }
return (checkKeyInInfo("directors") && this.info.directors.map((i) => i.name)) || [];
};
this.getProducerNames = function () {
return (checkKeyInInfo("producers") && this.info.producers.map((i) => i.name)) || [];
};
this.getCreatorNames = function () {
return (checkKeyInInfo("created_by") && this.info.created_by.map((i) => i.name)) || [];
};
this.getSpokenLanguagesEnglishNames = function () {
return (
(checkKeyInInfo("spoken_languages") &&
this.info.spoken_languages.map((i) => i.english_name)) ||
[]
);
};
this.getSpokenLanguagesOriginalNames = function () {
return (
(checkKeyInInfo("spoken_languages") && this.info.spoken_languages.map((i) => i.name)) || []
);
};
this.getSpokenLanguagesIsos = function () {
return (
(checkKeyInInfo("spoken_languages") && this.info.spoken_languages.map((i) => i.iso)) || []
);
};
this.getCompanyNames = function () {
return (
(checkKeyInInfo("production_companies") &&
this.info.production_companies.map((i) => i.name)) ||
[]
);
};
this.getOriginCountry = function () {
return (checkKeyInInfo("origin_country") && this.info.origin_country[0]) || "";
};
this.getCountries = function () {
return (checkKeyInInfo("production_countries") && this.info.production_countries) || [];
};
this.getCountryNames = function () {
return (
(checkKeyInInfo("production_countries") &&
this.info.production_countries.map((i) => i.name)) ||
[]
);
};
this.getCountryIsos = function () {
return (
(checkKeyInInfo("production_countries") &&
this.info.production_countries.map((i) => i.iso)) ||
[]
);
};
this.getNetworkNames = function () {
return (checkKeyInInfo("networks") && this.info.networks.map((i) => i.name)) || [];
};
this.getMediaInfoWidthValue = function () {
if (Object.keys(this.mediaInfo).length === 0) {
return 0;
}
return Number(this.mediaInfo.Video[0].Width.replace(" pixels", "").replace(" ", ""));
};
this.getMediaInfoHeightValue = function () {
if (Object.keys(this.mediaInfo).length === 0) {
return 0;
}
return Number(this.mediaInfo.Video[0].Height.replace(" pixels", "").replace(" ", ""));
};
/**
* Extract Info from the Inputted IMDB/TMDB URL or ID
*
* @param {string} input TMDB/IMDB URL or ID.
* @return {{imdb_id: string,
* tmdb_id: string,
* media_type: string
* input_source: string,}} imdb_id, tmdb_id, input_source(imdb/themoviedb), type(movie/tv)
*/
const extractUrlInfo = (url) => {
if (typeof url === "undefined" || url === "") {
throw Error("url not Provided");
}
if (typeof url !== "string") {
throw TypeError("Expected a String, got a(n)" + typeof url + "instead");
}
// let output = new urlInfo();
let output = {
imdb_id: "",
tmdb_id: "",
media_type: "",
input_source: "",
};
const imdbRe = new RegExp(
`(?:(?:http(?:s)?:\\/\\/)?(?:www.)?imdb\\.com\\/title\\/)?(?<id>tt\\d{7,8})`
);
const tmdbUrlRe = new RegExp(
`(?:http(?:s)?:\\/\\/)?(?:www.)?themoviedb\\.org\\/(?<media_type>\\S+)\\/(?<id>\\d+)`
);
const tmdbIdRe = new RegExp(`^(?<media_type>m|t|tv)(?<id>\\d+)`);
if (imdbRe.test(url)) {
output.input_source = "imdb";
output.imdb_id = imdbRe.exec(url).groups.id;
} else if (tmdbUrlRe.test(url)) {
output.input_source = "tmdb";
output.media_type = tmdbUrlRe.exec(url).groups.media_type;
output.tmdb_id = tmdbUrlRe.exec(url).groups.id;
} else if (tmdbIdRe.test(url)) {
output.input_source = "tmdb";
output.tmdb_id = tmdbIdRe.exec(url).groups.id;
output.media_type = tmdbIdRe
.exec(url)
.groups.media_type.replace("m", "movie")
.replace(/t$/gi, "tv");
} else {
return false;
throw Error("URL invalid. Make sure you are passing a TMDB/IMDB Url or Id");
}
// const re = /.*(?<input_source>imdb|themoviedb)\.(?:com|org)\/(?<type>\S+)\/(?<id>tt\d+|\d+).*|(?<imdb_id>tt\d+)|(?<tmdb_id>\d+)/g;
// const re =
// /(?:.*(?<input_source>imdb|themoviedb)\.(?:com|org)\/(?<media_type>\S+)\/){0,1}(?<id>tt\d+|\d+)/gm;
// const {
// groups: { input_source, media_type, id },
// } = re.exec(url);
// if (input_source === "imdb" || /tt\d+/g.test(id)) {
// output.imdb_id = id;
// output.input_source = "imdb";
// } else if (input_source === "themoviedb" || /(?:m|t|tv)\d+/.test(url.toLocaleLowerCase())) {
// output.tmdb_id = id;
// output.input_source = "tmdb";
// if (/(?:m)\d+/.test(url.toLocaleLowerCase())) {
// output.media_type = "movie";
// } else if (/(?:t|tv)\d+/.test(url.toLocaleLowerCase())) {
// output.media_type = "tv";
// } else output.media_type = media_type ? media_type : "";
// } else {
// throw Error("URL invalid. Make sure you are passing a TMDB/IMDB Url or Id");
// }
return output;
};
const extractTorrentNameInfo = (name) => {
let output = {
name: "",
resolution: "",
season: "",
episode: "",
criterion: "",
remux: "",
release_group: "",
media_type: "",
};
if (typeof Utilities.simpleRExtractor == "undefined") {
throw Error("Utilities.simpleRExtractor is not defined");
}
output.name = name;
output.resolution = Utilities.simpleRExtractor.extractResolution(name);
output.season = Utilities.simpleRExtractor.extractSeason(name);
output.criterion = Utilities.simpleRExtractor.extractCriterion(name);
output.remux = Utilities.simpleRExtractor.extractRemux(name);
output.release_group = Utilities.simpleRExtractor.extractReleaseGroup(name);
output.media_type = output.season ? "tv" : "movie";
output.episode = Utilities.simpleRExtractor.extractEpisode(name);
return output;
};
/**
/**
* Fills the info with values of keys that match infoTemplate
*
* @param {object} data Object containing same keys as info
* @return {Array} List of Keys that were updated
*/
const setInfo = (data) => {
let oldKeys = Object.keys(this.info);
for (const key in data) {
// if(typeof info[key] === "string" && info[key] !== "") continue;
// if(Array.isArray(info[key]) && info[key] !== []) continue;
if (infoTemplate.hasOwnProperty(key)) {
this.info[key] = data[key];
}
}
return Object.keys(this.info).filter((k) => !oldKeys.includes(k));
};
const checkKeyInInfo = (prop) => {
return this.info != null && Object.keys(this.info).length > 0 && this.info.hasOwnProperty(prop);
};
const fillTmdbInfo = (data) => {
if (Object.keys(data).length === 0) return;
this.success = true;
setInfo(data);
if (!Object.keys(this.info).includes("ratings")) {
this.info.ratings = {};
}
this.info.tmdb_id = data.id || "";
if (!this.info.imdb_id) {
if (Object.keys(data.external_ids).includes("imdb_id") && data.external_ids.imdb_id != null) {
this.info.imdb_id = data.external_ids.imdb_id || "";
}
}
this.info.title = data.title || data.name || "";
this.info.original_title = data.original_title || data.original_name || "";
this.info.directors = getTMDBDirectors(data);
this.info.year = getTMDBYear(data);
if (data.poster_path) {
this.info.poster_url = `${tmdb.config.image_url}${data.poster_path}`;
}
this.info.backdrop_url = `${tmdb.config.image_url}${data.backdrop_path}`;
this.info.tmdb_rating =
data.vote_average && !isNaN(data.vote_average) ? (data.vote_average * 10).toString() : "";
this.info.ratings.tmdb =
data.vote_average && !isNaN(data.vote_average) ? (data.vote_average * 10).toString() : "";
this.info.release_date = getTMDBReleaseDate(data);
this.info.trailer_url = getTMDBTrailerUrl(data);
this.info.producers = getTMDBProducers(data);
this.info.production_companies = getTMDBProductionCompanies(data);
this.info.production_countries = getTMDBProductionCountries(data);
this.info.spoken_languages = getTMDBSpokenLanguages(data);
this.info.writers = getTMDBWriters(data);
cleanInfo();
};
const fillOmdbInfo = (data) => {
if (data == null) return;
if (!Object.keys(this.info).includes("ratings")) {
this.info.ratings = {};