react-native-consumet 1.0.0-rc.0 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/generated/java/com/consumet/NativeConsumetSpec.java +4 -0
- package/android/generated/jni/RNConsumetSpec-generated.cpp +6 -0
- package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI-generated.cpp +8 -0
- package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI.h +9 -0
- package/android/src/main/java/com/consumet/ConsumetModule.kt +7 -0
- package/android/src/main/java/com/consumet/DdosGuardModule.kt +248 -189
- package/ios/generated/RNConsumetSpec/RNConsumetSpec-generated.mm +7 -0
- package/ios/generated/RNConsumetSpec/RNConsumetSpec.h +2 -0
- package/ios/generated/RNConsumetSpecJSI-generated.cpp +8 -0
- package/ios/generated/RNConsumetSpecJSI.h +9 -0
- package/lib/commonjs/NativeConsumet.ts +28 -26
- package/lib/commonjs/extension-registry.json +13 -13
- package/lib/commonjs/extractors/filemoon.js +2 -2
- package/lib/commonjs/extractors/kwik.js +60 -15
- package/lib/commonjs/extractors/kwik.js.map +1 -1
- package/lib/commonjs/extractors/megacloud.js +6 -6
- package/lib/commonjs/index.js +2 -11
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/types.js +4 -4
- package/lib/commonjs/models/video-extractor.js +4 -4
- package/lib/commonjs/providers/anime/animedrive.js +12 -12
- package/lib/commonjs/providers/anime/animekai.js +41 -41
- package/lib/commonjs/providers/anime/animepahe/animepahe.js +16 -15
- package/lib/commonjs/providers/anime/animepahe/animepahe.js.map +1 -1
- package/lib/commonjs/providers/anime/animepahe/create-animepahe.js +12 -9
- package/lib/commonjs/providers/anime/animepahe/create-animepahe.js.map +1 -1
- package/lib/commonjs/providers/anime/animesuge/animesuge.js +78 -0
- package/lib/commonjs/providers/anime/animesuge/animesuge.js.map +1 -0
- package/lib/commonjs/providers/anime/animesuge/create-animesuge.js +312 -0
- package/lib/commonjs/providers/anime/animesuge/create-animesuge.js.map +1 -0
- package/lib/commonjs/providers/anime/animeunity.js +13 -13
- package/lib/commonjs/providers/anime/index.js +4 -4
- package/lib/commonjs/providers/anime/index.js.map +1 -1
- package/lib/commonjs/providers/anime/marin.js +12 -12
- package/lib/commonjs/providers/anime/zoro/create-zoro.js +2 -2
- package/lib/commonjs/providers/anime/zoro/create-zoro.js.map +1 -1
- package/lib/commonjs/providers/anime/zoro/zoro.js +76 -74
- package/lib/commonjs/providers/anime/zoro/zoro.js.map +1 -1
- package/lib/commonjs/providers/manga/brmangas.js +3 -3
- package/lib/commonjs/providers/meta/anilist.js +91 -91
- package/lib/commonjs/providers/meta/mal.js +12 -12
- package/lib/commonjs/providers/meta/tmdb.js +21 -21
- package/lib/commonjs/providers/movies/himovies/create-himovies.js +16 -16
- package/lib/commonjs/providers/movies/himovies/himovies.js +16 -16
- package/lib/commonjs/providers/movies/multimovies.js +15 -15
- package/lib/commonjs/providers/movies/multistream/index.js +21 -20
- package/lib/commonjs/providers/movies/multistream/index.js.map +1 -1
- package/lib/commonjs/providers/movies/multistream/utils.js +142 -130
- package/lib/commonjs/providers/movies/multistream/utils.js.map +1 -1
- package/lib/commonjs/utils/ExtractorManager.js +15 -15
- package/lib/commonjs/utils/ExtractorManager.js.map +1 -1
- package/lib/commonjs/utils/ProviderManager.js +2 -1
- package/lib/commonjs/utils/ProviderManager.js.map +1 -1
- package/lib/commonjs/utils/create-extractor-context.js +9 -1
- package/lib/commonjs/utils/create-extractor-context.js.map +1 -1
- package/lib/commonjs/utils/create-provider-context.js +6 -2
- package/lib/commonjs/utils/create-provider-context.js.map +1 -1
- package/lib/commonjs/utils/extension-utils.js +44 -54
- package/lib/commonjs/utils/extension-utils.js.map +1 -1
- package/lib/commonjs/utils/index.js +2 -2
- package/lib/commonjs/utils/provider-maps.js +31 -0
- package/lib/commonjs/utils/provider-maps.js.map +1 -0
- package/lib/commonjs/utils/providers-list.js +4 -4
- package/lib/commonjs/utils/url-polyfill.js +4 -4
- package/lib/module/NativeConsumet.ts +28 -26
- package/lib/module/extension-registry.json +13 -13
- package/lib/module/extractors/filemoon.js +2 -2
- package/lib/module/extractors/kwik.js +60 -15
- package/lib/module/extractors/kwik.js.map +1 -1
- package/lib/module/extractors/megacloud.js +6 -6
- package/lib/module/index.js +3 -7
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/types.js +4 -4
- package/lib/module/models/video-extractor.js +4 -4
- package/lib/module/providers/anime/animedrive.js +12 -12
- package/lib/module/providers/anime/animekai.js +41 -41
- package/lib/module/providers/anime/animepahe/animepahe.js +14 -14
- package/lib/module/providers/anime/animepahe/animepahe.js.map +1 -1
- package/lib/module/providers/anime/animepahe/create-animepahe.js +13 -9
- package/lib/module/providers/anime/animepahe/create-animepahe.js.map +1 -1
- package/lib/module/providers/anime/animesuge/animesuge.js +73 -0
- package/lib/module/providers/anime/animesuge/animesuge.js.map +1 -0
- package/lib/module/providers/anime/animesuge/create-animesuge.js +309 -0
- package/lib/module/providers/anime/animesuge/create-animesuge.js.map +1 -0
- package/lib/module/providers/anime/animeunity.js +13 -13
- package/lib/module/providers/anime/index.js +2 -2
- package/lib/module/providers/anime/index.js.map +1 -1
- package/lib/module/providers/anime/marin.js +12 -12
- package/lib/module/providers/anime/zoro/create-zoro.js +3 -2
- package/lib/module/providers/anime/zoro/create-zoro.js.map +1 -1
- package/lib/module/providers/anime/zoro/zoro.js +74 -73
- package/lib/module/providers/anime/zoro/zoro.js.map +1 -1
- package/lib/module/providers/manga/brmangas.js +3 -3
- package/lib/module/providers/meta/anilist.js +91 -91
- package/lib/module/providers/meta/mal.js +12 -12
- package/lib/module/providers/meta/tmdb.js +21 -21
- package/lib/module/providers/movies/himovies/create-himovies.js +16 -16
- package/lib/module/providers/movies/himovies/himovies.js +16 -16
- package/lib/module/providers/movies/multimovies.js +15 -15
- package/lib/module/providers/movies/multistream/index.js +21 -20
- package/lib/module/providers/movies/multistream/index.js.map +1 -1
- package/lib/module/providers/movies/multistream/utils.js +141 -129
- package/lib/module/providers/movies/multistream/utils.js.map +1 -1
- package/lib/module/utils/ExtractorManager.js +16 -16
- package/lib/module/utils/ExtractorManager.js.map +1 -1
- package/lib/module/utils/ProviderManager.js +2 -1
- package/lib/module/utils/ProviderManager.js.map +1 -1
- package/lib/module/utils/create-extractor-context.js +10 -1
- package/lib/module/utils/create-extractor-context.js.map +1 -1
- package/lib/module/utils/create-provider-context.js +8 -4
- package/lib/module/utils/create-provider-context.js.map +1 -1
- package/lib/module/utils/extension-utils.js +23 -33
- package/lib/module/utils/extension-utils.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/provider-maps.js +27 -0
- package/lib/module/utils/provider-maps.js.map +1 -0
- package/lib/module/utils/providers-list.js +4 -4
- package/lib/module/utils/url-polyfill.js +4 -4
- package/lib/typescript/commonjs/src/NativeConsumet.d.ts +2 -0
- package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/extractors/kwik.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +6 -6
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/extractor-context.d.ts +8 -0
- package/lib/typescript/commonjs/src/models/extractor-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/models/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/provider-context.d.ts +6 -2
- package/lib/typescript/commonjs/src/models/provider-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animepahe/animepahe.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animesuge/animesuge.d.ts +34 -0
- package/lib/typescript/commonjs/src/providers/anime/animesuge/animesuge.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/providers/anime/animesuge/create-animesuge.d.ts +14 -0
- package/lib/typescript/commonjs/src/providers/anime/animesuge/create-animesuge.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/providers/anime/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/providers/anime/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/zoro/create-zoro.d.ts +1 -1
- package/lib/typescript/commonjs/src/providers/anime/zoro/create-zoro.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/zoro/zoro.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts +1 -1
- package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts +2 -2
- package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/ProviderManager.d.ts +1 -1
- package/lib/typescript/commonjs/src/utils/ProviderManager.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/create-extractor-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/create-provider-context.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/extension-utils.d.ts +1 -20
- package/lib/typescript/commonjs/src/utils/extension-utils.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/index.d.ts +2 -1
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/provider-maps.d.ts +27 -0
- package/lib/typescript/commonjs/src/utils/provider-maps.d.ts.map +1 -0
- package/lib/typescript/module/src/NativeConsumet.d.ts +2 -0
- package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
- package/lib/typescript/module/src/extractors/kwik.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +6 -6
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/models/extractor-context.d.ts +8 -0
- package/lib/typescript/module/src/models/extractor-context.d.ts.map +1 -1
- package/lib/typescript/module/src/models/index.d.ts +2 -2
- package/lib/typescript/module/src/models/index.d.ts.map +1 -1
- package/lib/typescript/module/src/models/provider-context.d.ts +6 -2
- package/lib/typescript/module/src/models/provider-context.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/animepahe/animepahe.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts +1 -1
- package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/animesuge/animesuge.d.ts +34 -0
- package/lib/typescript/module/src/providers/anime/animesuge/animesuge.d.ts.map +1 -0
- package/lib/typescript/module/src/providers/anime/animesuge/create-animesuge.d.ts +14 -0
- package/lib/typescript/module/src/providers/anime/animesuge/create-animesuge.d.ts.map +1 -0
- package/lib/typescript/module/src/providers/anime/index.d.ts +2 -2
- package/lib/typescript/module/src/providers/anime/index.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/zoro/create-zoro.d.ts +1 -1
- package/lib/typescript/module/src/providers/anime/zoro/create-zoro.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/zoro/zoro.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/movies/multistream/index.d.ts +1 -1
- package/lib/typescript/module/src/providers/movies/multistream/index.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts +2 -2
- package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/ProviderManager.d.ts +1 -1
- package/lib/typescript/module/src/utils/ProviderManager.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/create-extractor-context.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/create-provider-context.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/extension-utils.d.ts +1 -20
- package/lib/typescript/module/src/utils/extension-utils.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/index.d.ts +2 -1
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/provider-maps.d.ts +27 -0
- package/lib/typescript/module/src/utils/provider-maps.d.ts.map +1 -0
- package/package.json +6 -2
- package/src/NativeConsumet.ts +2 -0
- package/src/extension-registry.json +81 -81
- package/src/extractors/StreamP2P.ts +60 -60
- package/src/extractors/filemoon.ts +58 -58
- package/src/extractors/index.ts +41 -41
- package/src/extractors/kwik.ts +113 -50
- package/src/extractors/megacloud.ts +163 -163
- package/src/extractors/mixdrop.ts +31 -31
- package/src/extractors/mp4upload.ts +31 -31
- package/src/extractors/streamhub.ts +58 -58
- package/src/extractors/streamwish.ts +120 -120
- package/src/extractors/vidhide.ts +59 -59
- package/src/index.tsx +176 -175
- package/src/models/extension-manifest.ts +77 -77
- package/src/models/extractor-context.ts +55 -41
- package/src/models/index.ts +107 -106
- package/src/models/provider-context.ts +192 -182
- package/src/models/types.ts +531 -531
- package/src/models/video-extractor.ts +48 -48
- package/src/providers/anime/animedrive.ts +245 -245
- package/src/providers/anime/animekai.ts +627 -627
- package/src/providers/anime/animepahe/animepahe.ts +76 -76
- package/src/providers/anime/animepahe/create-animepahe.ts +350 -348
- package/src/providers/anime/animesuge/animesuge.ts +77 -0
- package/src/providers/anime/animesuge/create-animesuge.ts +327 -0
- package/src/providers/anime/animeunity.ts +216 -216
- package/src/providers/anime/index.ts +21 -21
- package/src/providers/anime/marin.ts +319 -319
- package/src/providers/anime/zoro/create-zoro.ts +656 -655
- package/src/providers/anime/zoro/zoro.ts +198 -197
- package/src/providers/index.ts +7 -7
- package/src/providers/manga/brmangas.ts +144 -144
- package/src/providers/meta/anilist.ts +2108 -2108
- package/src/providers/meta/mal.ts +635 -635
- package/src/providers/meta/tmdb.ts +470 -470
- package/src/providers/movies/himovies/create-himovies.ts +529 -529
- package/src/providers/movies/himovies/himovies.ts +90 -90
- package/src/providers/movies/index.ts +15 -15
- package/src/providers/movies/multimovies.ts +495 -495
- package/src/providers/movies/multistream/index.ts +232 -231
- package/src/providers/movies/multistream/utils.ts +147 -270
- package/src/utils/ExtractorManager.ts +311 -311
- package/src/utils/ProviderManager.ts +423 -424
- package/src/utils/create-extractor-context.ts +36 -22
- package/src/utils/create-provider-context.ts +117 -107
- package/src/utils/extension-utils.ts +105 -114
- package/src/utils/index.ts +96 -95
- package/src/utils/provider-maps.ts +31 -0
- package/src/utils/providers-list.ts +27 -27
- package/src/utils/url-polyfill.ts +642 -642
- package/src/utils/utils.ts +374 -374
package/src/utils/utils.ts
CHANGED
|
@@ -1,374 +1,374 @@
|
|
|
1
|
-
import { compareTwoStrings } from 'string-similarity';
|
|
2
|
-
// import sharp from 'sharp';
|
|
3
|
-
import { load } from 'cheerio';
|
|
4
|
-
// import * as blurhash from 'blurhash';
|
|
5
|
-
|
|
6
|
-
export const USER_AGENT =
|
|
7
|
-
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
|
|
8
|
-
export const days = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
|
9
|
-
export const ANIFY_URL = 'https://anify.eltik.cc';
|
|
10
|
-
|
|
11
|
-
export const splitAuthor = (authors: string) => {
|
|
12
|
-
const res: string[] = [];
|
|
13
|
-
let eater = '';
|
|
14
|
-
for (let i = 0; i < authors.length; i++) {
|
|
15
|
-
if (authors[i] === ' ' && (authors[i - 1] === ',' || authors[i - 1] === ';')) {
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
if (authors[i] === ',' || authors[i] === ';') {
|
|
19
|
-
res.push(eater.trim());
|
|
20
|
-
eater = '';
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
eater += authors[i];
|
|
24
|
-
}
|
|
25
|
-
res.push(eater);
|
|
26
|
-
return res;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const floorID = (id: string) => {
|
|
30
|
-
let imp = '';
|
|
31
|
-
for (let i = 0; i < id?.length - 3; i++) {
|
|
32
|
-
imp += id[i];
|
|
33
|
-
}
|
|
34
|
-
const idV = parseInt(imp);
|
|
35
|
-
return idV * 1000;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const formatTitle = (title: string) => {
|
|
39
|
-
const result = title.replace(/[0-9]/g, '');
|
|
40
|
-
return result.trim();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const genElement = (s: string, e: string) => {
|
|
44
|
-
if (s === '') return;
|
|
45
|
-
const $ = load(e);
|
|
46
|
-
let i = 0;
|
|
47
|
-
let str = '';
|
|
48
|
-
let el = $();
|
|
49
|
-
for (; i < s.length; i++) {
|
|
50
|
-
if (s[i] === ' ') {
|
|
51
|
-
el = $(str);
|
|
52
|
-
str = '';
|
|
53
|
-
i++;
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
str += s[i];
|
|
57
|
-
}
|
|
58
|
-
for (; i < s.length; i++) {
|
|
59
|
-
if (s[i] === ' ') {
|
|
60
|
-
el = $(el).children(str);
|
|
61
|
-
str = '';
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
str += s[i];
|
|
65
|
-
}
|
|
66
|
-
el = $(el).children(str);
|
|
67
|
-
return el;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const range = ({ from = 0, to = 0, step = 1, length = Math.ceil((to - from) / step) }) =>
|
|
71
|
-
Array.from({ length }, (_, i) => from + i * step);
|
|
72
|
-
|
|
73
|
-
export const capitalizeFirstLetter = (s: string) => s?.charAt(0).toUpperCase() + s.slice(1);
|
|
74
|
-
|
|
75
|
-
export const getDays = (day1: string, day2: string) => {
|
|
76
|
-
const day1Index = days.indexOf(capitalizeFirstLetter(day1)) - 1;
|
|
77
|
-
const day2Index = days.indexOf(capitalizeFirstLetter(day2)) - 1;
|
|
78
|
-
const now = new Date();
|
|
79
|
-
const day1Date = new Date();
|
|
80
|
-
const day2Date = new Date();
|
|
81
|
-
day1Date.setDate(now.getDate() + ((day1Index + 7 - now.getDay()) % 7));
|
|
82
|
-
day2Date.setDate(now.getDate() + ((day2Index + 7 - now.getDay()) % 7));
|
|
83
|
-
day1Date.setHours(0, 0, 0, 0);
|
|
84
|
-
day2Date.setHours(0, 0, 0, 0);
|
|
85
|
-
return [day1Date.getTime() / 1000, day2Date.getTime() / 1000];
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const isJson = (str: string) => {
|
|
89
|
-
try {
|
|
90
|
-
JSON.parse(str);
|
|
91
|
-
} catch (e) {
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export function convertDuration(milliseconds: number) {
|
|
98
|
-
let seconds = Math.floor(milliseconds / 1000);
|
|
99
|
-
let minutes = Math.floor(seconds / 60);
|
|
100
|
-
const hours = Math.floor(minutes / 60);
|
|
101
|
-
|
|
102
|
-
seconds = seconds % 60;
|
|
103
|
-
minutes = minutes % 60;
|
|
104
|
-
|
|
105
|
-
return `PT${hours}H${minutes}M${seconds}S`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export const calculateStringSimilarity = (first: string, second: string): number => {
|
|
109
|
-
first = first.replace(/\s+/g, '');
|
|
110
|
-
second = second.replace(/\s+/g, '');
|
|
111
|
-
|
|
112
|
-
if (first === second) return 1; // identical or empty
|
|
113
|
-
if (first.length < 2 || second.length < 2) return 0; // if either is a 0-letter or 1-letter string
|
|
114
|
-
|
|
115
|
-
const firstBigrams = new Map();
|
|
116
|
-
for (let i = 0; i < first.length - 1; i++) {
|
|
117
|
-
const bigram = first.substring(i, i + 2);
|
|
118
|
-
const count = firstBigrams.has(bigram) ? firstBigrams.get(bigram) + 1 : 1;
|
|
119
|
-
|
|
120
|
-
firstBigrams.set(bigram, count);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let intersectionSize = 0;
|
|
124
|
-
for (let i = 0; i < second.length - 1; i++) {
|
|
125
|
-
const bigram = second.substring(i, i + 2);
|
|
126
|
-
const count = firstBigrams.has(bigram) ? firstBigrams.get(bigram) : 0;
|
|
127
|
-
|
|
128
|
-
if (count > 0) {
|
|
129
|
-
firstBigrams.set(bigram, count - 1);
|
|
130
|
-
intersectionSize++;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return (2.0 * intersectionSize) / (first.length + second.length - 2);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const substringAfter = (str: string, toFind: string) => {
|
|
138
|
-
const index = str.indexOf(toFind);
|
|
139
|
-
return index === -1 ? '' : str.substring(index + toFind.length);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export const substringBefore = (str: string, toFind: string) => {
|
|
143
|
-
const index = str.indexOf(toFind);
|
|
144
|
-
return index === -1 ? '' : str.substring(0, index);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export const substringAfterLast = (str: string, toFind: string) => {
|
|
148
|
-
const index = str.lastIndexOf(toFind);
|
|
149
|
-
return index === -1 ? '' : str.substring(index + toFind.length);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export const substringBeforeLast = (str: string, toFind: string) => {
|
|
153
|
-
const index = str.lastIndexOf(toFind);
|
|
154
|
-
return index === -1 ? '' : str.substring(0, index);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// const generateHash = async (url: string) => {
|
|
158
|
-
// let returnedBuffer;
|
|
159
|
-
|
|
160
|
-
// const response = await fetch(url);
|
|
161
|
-
// const arrayBuffer = await response.arrayBuffer();
|
|
162
|
-
// returnedBuffer = Buffer.from(arrayBuffer);
|
|
163
|
-
|
|
164
|
-
// // const { info, data } = await sharp(returnedBuffer).ensureAlpha().raw().toBuffer({
|
|
165
|
-
// // resolveWithObject: true,
|
|
166
|
-
// // });
|
|
167
|
-
|
|
168
|
-
// return blurhash.encode(new Uint8ClampedArray(data), info.width, info.height, 4, 3);
|
|
169
|
-
// };
|
|
170
|
-
|
|
171
|
-
export const getHashFromImage = (url: string) => {
|
|
172
|
-
if (url?.length === 0) {
|
|
173
|
-
return '';
|
|
174
|
-
} else {
|
|
175
|
-
// let hash!: string;
|
|
176
|
-
// generateHash(url).then(hashKey => (hash = hashKey));
|
|
177
|
-
return 'hash';
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// Function to find similar titles
|
|
182
|
-
export function findSimilarTitles(inputTitle: string, titles: any[]): any[] {
|
|
183
|
-
const results: (any & { similarity: number })[] = [];
|
|
184
|
-
|
|
185
|
-
titles?.forEach((titleObj: any) => {
|
|
186
|
-
const title = cleanTitle(
|
|
187
|
-
titleObj?.title
|
|
188
|
-
?.toLowerCase()
|
|
189
|
-
?.replace(/\([^\)]*\)/g, '')
|
|
190
|
-
.trim() || ''
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
// Calculate similarity score between inputTitle and title
|
|
194
|
-
const similarity = compareTwoStrings(cleanTitle(inputTitle?.toLowerCase() || ''), title);
|
|
195
|
-
|
|
196
|
-
if (similarity > 0.6) {
|
|
197
|
-
results.push({ ...titleObj, similarity });
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
const isSubAvailable = results.some((result) => result.episodes && result.episodes.sub > 0);
|
|
202
|
-
|
|
203
|
-
// If episodes.sub is available, sort the results
|
|
204
|
-
if (isSubAvailable) {
|
|
205
|
-
return results.sort((a, b) => {
|
|
206
|
-
// First sort by similarity in descending order
|
|
207
|
-
if (b.similarity !== a.similarity) {
|
|
208
|
-
return b.similarity - a.similarity;
|
|
209
|
-
}
|
|
210
|
-
// If similarity is the same, sort by episodes.sub in descending order
|
|
211
|
-
return (b.episodes?.sub || 0) - (a.episodes?.sub || 0);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// If episodes.sub is not available, return the original list
|
|
216
|
-
return results.sort((a, b) => b.similarity - a.similarity);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Function to convert Roman numerals to Arabic numbers
|
|
220
|
-
function romanToArabic(roman: string): number {
|
|
221
|
-
const romanMap: Record<string, number> = {
|
|
222
|
-
i: 1,
|
|
223
|
-
v: 5,
|
|
224
|
-
x: 10,
|
|
225
|
-
l: 50,
|
|
226
|
-
c: 100,
|
|
227
|
-
d: 500,
|
|
228
|
-
m: 1000,
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
roman = roman.toLowerCase();
|
|
232
|
-
let result = 0;
|
|
233
|
-
|
|
234
|
-
for (let i = 0; i < roman.length; i++) {
|
|
235
|
-
const current = romanMap[roman[i]!]!;
|
|
236
|
-
const next = romanMap[roman[i + 1]!];
|
|
237
|
-
|
|
238
|
-
if (next && current < next) {
|
|
239
|
-
result += next - current;
|
|
240
|
-
i++;
|
|
241
|
-
} else {
|
|
242
|
-
result += current;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return result;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
export function cleanTitle(title: string | undefined | null): string {
|
|
250
|
-
if (!title) return '';
|
|
251
|
-
|
|
252
|
-
return transformSpecificVariations(
|
|
253
|
-
removeSpecialChars(
|
|
254
|
-
title
|
|
255
|
-
.replace(/[^A-Za-z0-9!@#$%^&*() ]/gim, ' ')
|
|
256
|
-
.replace(/(th|rd|nd|st) (Season|season)/gim, '')
|
|
257
|
-
.replace(/\([^\(]*\)$/gim, '')
|
|
258
|
-
.replace(/season/g, '')
|
|
259
|
-
.replace(/\b(IX|IV|V?I{0,3})\b/gi, (match: any) => romanToArabic(match).toString())
|
|
260
|
-
.replace(/ {2}/g, ' ')
|
|
261
|
-
.replace(/"/g, '')
|
|
262
|
-
.trimEnd()
|
|
263
|
-
)
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export function removeSpecialChars(title: string | undefined | null): string {
|
|
268
|
-
if (!title) return '';
|
|
269
|
-
|
|
270
|
-
return title
|
|
271
|
-
.replace(/[^A-Za-z0-9!@#$%^&*()\-= ]/gim, ' ')
|
|
272
|
-
.replace(/[^A-Za-z0-9\-= ]/gim, '')
|
|
273
|
-
.replace(/ {2}/g, ' ');
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export function transformSpecificVariations(title: string | undefined | null): string {
|
|
277
|
-
if (!title) return '';
|
|
278
|
-
|
|
279
|
-
return title.replace(/yuu/g, 'yu').replace(/ ou/g, ' oh');
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export function sanitizeTitle(title: string): string {
|
|
283
|
-
let resTitle = title.replace(/ *(\(dub\)|\(sub\)|\(uncensored\)|\(uncut\)|\(subbed\)|\(dubbed\))/i, '');
|
|
284
|
-
resTitle = resTitle.replace(/ *\([^)]+audio\)/i, '');
|
|
285
|
-
resTitle = resTitle.replace(/ BD( |$)/i, '');
|
|
286
|
-
resTitle = resTitle.replace(/\(TV\)/g, '');
|
|
287
|
-
resTitle = resTitle.trim();
|
|
288
|
-
resTitle = resTitle.substring(0, 99); // truncate
|
|
289
|
-
return resTitle;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export function stringSearch(string: string, pattern: string): number {
|
|
293
|
-
let count = 0;
|
|
294
|
-
string = string.toLowerCase();
|
|
295
|
-
pattern = pattern.toLowerCase();
|
|
296
|
-
string = string.replace(/[^a-zA-Z0-9 -]/g, '');
|
|
297
|
-
pattern = pattern.replace(/[^a-zA-Z0-9 -]/g, '');
|
|
298
|
-
|
|
299
|
-
for (let i = 0; i < string.length; i++) {
|
|
300
|
-
for (let j = 0; j < pattern.length; j++) {
|
|
301
|
-
if (pattern[j] !== string[i + j]) break;
|
|
302
|
-
if (j === pattern.length - 1) count++;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return count;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
interface FilterOptions {
|
|
309
|
-
timeout?: number;
|
|
310
|
-
headers?: Record<string, string>;
|
|
311
|
-
indicators?: string[];
|
|
312
|
-
concurrency?: number;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export const filterValidM3U8 = async (m3u8Links: string[], options: FilterOptions = {}): Promise<string[]> => {
|
|
316
|
-
const {
|
|
317
|
-
timeout = 10000,
|
|
318
|
-
headers = {},
|
|
319
|
-
indicators = ['#EXT', '#EXTINF', '#EXT-X-', '#EXTM3U'],
|
|
320
|
-
concurrency = 10,
|
|
321
|
-
} = options;
|
|
322
|
-
|
|
323
|
-
const validLinks: string[] = [];
|
|
324
|
-
let index = 0;
|
|
325
|
-
|
|
326
|
-
const next = async (): Promise<void> => {
|
|
327
|
-
while (index < m3u8Links.length) {
|
|
328
|
-
const currentIndex = index++;
|
|
329
|
-
const url = m3u8Links[currentIndex]!;
|
|
330
|
-
|
|
331
|
-
const controller = new AbortController();
|
|
332
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
333
|
-
|
|
334
|
-
try {
|
|
335
|
-
const response = await fetch(url, {
|
|
336
|
-
headers: {
|
|
337
|
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
338
|
-
...headers,
|
|
339
|
-
},
|
|
340
|
-
signal: controller.signal,
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
clearTimeout(timeoutId);
|
|
344
|
-
|
|
345
|
-
if (!response.ok) {
|
|
346
|
-
// console.warn(`❌ HTTP error (${response.status}) for ${url}`);
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// Optional shortcut: skip non-M3U8 content types
|
|
351
|
-
const contentType = response.headers.get('content-type');
|
|
352
|
-
if (contentType && !contentType.includes('application/vnd.apple.mpegurl') && !contentType.includes('mpegurl')) {
|
|
353
|
-
// console.info(`⚠️ Skipping non-M3U8 type: ${url}`);
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
const content = await response.text();
|
|
358
|
-
if (indicators.some((ind) => content.includes(ind))) {
|
|
359
|
-
validLinks.push(url);
|
|
360
|
-
} else {
|
|
361
|
-
// console.info(`⚠️ No M3U8 indicators found in: ${url}`);
|
|
362
|
-
}
|
|
363
|
-
} catch (err: any) {
|
|
364
|
-
clearTimeout(timeoutId);
|
|
365
|
-
const reason = err.name === 'AbortError' ? 'timeout' : err.message;
|
|
366
|
-
// console.warn(`⚠️ Failed to validate M3U8 (${url}): ${reason}`);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
// Run N concurrent validators
|
|
372
|
-
await Promise.all(Array.from({ length: concurrency }, () => next()));
|
|
373
|
-
return validLinks;
|
|
374
|
-
};
|
|
1
|
+
import { compareTwoStrings } from 'string-similarity';
|
|
2
|
+
// import sharp from 'sharp';
|
|
3
|
+
import { load } from 'cheerio';
|
|
4
|
+
// import * as blurhash from 'blurhash';
|
|
5
|
+
|
|
6
|
+
export const USER_AGENT =
|
|
7
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
|
|
8
|
+
export const days = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
|
9
|
+
export const ANIFY_URL = 'https://anify.eltik.cc';
|
|
10
|
+
|
|
11
|
+
export const splitAuthor = (authors: string) => {
|
|
12
|
+
const res: string[] = [];
|
|
13
|
+
let eater = '';
|
|
14
|
+
for (let i = 0; i < authors.length; i++) {
|
|
15
|
+
if (authors[i] === ' ' && (authors[i - 1] === ',' || authors[i - 1] === ';')) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (authors[i] === ',' || authors[i] === ';') {
|
|
19
|
+
res.push(eater.trim());
|
|
20
|
+
eater = '';
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
eater += authors[i];
|
|
24
|
+
}
|
|
25
|
+
res.push(eater);
|
|
26
|
+
return res;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const floorID = (id: string) => {
|
|
30
|
+
let imp = '';
|
|
31
|
+
for (let i = 0; i < id?.length - 3; i++) {
|
|
32
|
+
imp += id[i];
|
|
33
|
+
}
|
|
34
|
+
const idV = parseInt(imp);
|
|
35
|
+
return idV * 1000;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const formatTitle = (title: string) => {
|
|
39
|
+
const result = title.replace(/[0-9]/g, '');
|
|
40
|
+
return result.trim();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const genElement = (s: string, e: string) => {
|
|
44
|
+
if (s === '') return;
|
|
45
|
+
const $ = load(e);
|
|
46
|
+
let i = 0;
|
|
47
|
+
let str = '';
|
|
48
|
+
let el = $();
|
|
49
|
+
for (; i < s.length; i++) {
|
|
50
|
+
if (s[i] === ' ') {
|
|
51
|
+
el = $(str);
|
|
52
|
+
str = '';
|
|
53
|
+
i++;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
str += s[i];
|
|
57
|
+
}
|
|
58
|
+
for (; i < s.length; i++) {
|
|
59
|
+
if (s[i] === ' ') {
|
|
60
|
+
el = $(el).children(str);
|
|
61
|
+
str = '';
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
str += s[i];
|
|
65
|
+
}
|
|
66
|
+
el = $(el).children(str);
|
|
67
|
+
return el;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const range = ({ from = 0, to = 0, step = 1, length = Math.ceil((to - from) / step) }) =>
|
|
71
|
+
Array.from({ length }, (_, i) => from + i * step);
|
|
72
|
+
|
|
73
|
+
export const capitalizeFirstLetter = (s: string) => s?.charAt(0).toUpperCase() + s.slice(1);
|
|
74
|
+
|
|
75
|
+
export const getDays = (day1: string, day2: string) => {
|
|
76
|
+
const day1Index = days.indexOf(capitalizeFirstLetter(day1)) - 1;
|
|
77
|
+
const day2Index = days.indexOf(capitalizeFirstLetter(day2)) - 1;
|
|
78
|
+
const now = new Date();
|
|
79
|
+
const day1Date = new Date();
|
|
80
|
+
const day2Date = new Date();
|
|
81
|
+
day1Date.setDate(now.getDate() + ((day1Index + 7 - now.getDay()) % 7));
|
|
82
|
+
day2Date.setDate(now.getDate() + ((day2Index + 7 - now.getDay()) % 7));
|
|
83
|
+
day1Date.setHours(0, 0, 0, 0);
|
|
84
|
+
day2Date.setHours(0, 0, 0, 0);
|
|
85
|
+
return [day1Date.getTime() / 1000, day2Date.getTime() / 1000];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const isJson = (str: string) => {
|
|
89
|
+
try {
|
|
90
|
+
JSON.parse(str);
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export function convertDuration(milliseconds: number) {
|
|
98
|
+
let seconds = Math.floor(milliseconds / 1000);
|
|
99
|
+
let minutes = Math.floor(seconds / 60);
|
|
100
|
+
const hours = Math.floor(minutes / 60);
|
|
101
|
+
|
|
102
|
+
seconds = seconds % 60;
|
|
103
|
+
minutes = minutes % 60;
|
|
104
|
+
|
|
105
|
+
return `PT${hours}H${minutes}M${seconds}S`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const calculateStringSimilarity = (first: string, second: string): number => {
|
|
109
|
+
first = first.replace(/\s+/g, '');
|
|
110
|
+
second = second.replace(/\s+/g, '');
|
|
111
|
+
|
|
112
|
+
if (first === second) return 1; // identical or empty
|
|
113
|
+
if (first.length < 2 || second.length < 2) return 0; // if either is a 0-letter or 1-letter string
|
|
114
|
+
|
|
115
|
+
const firstBigrams = new Map();
|
|
116
|
+
for (let i = 0; i < first.length - 1; i++) {
|
|
117
|
+
const bigram = first.substring(i, i + 2);
|
|
118
|
+
const count = firstBigrams.has(bigram) ? firstBigrams.get(bigram) + 1 : 1;
|
|
119
|
+
|
|
120
|
+
firstBigrams.set(bigram, count);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let intersectionSize = 0;
|
|
124
|
+
for (let i = 0; i < second.length - 1; i++) {
|
|
125
|
+
const bigram = second.substring(i, i + 2);
|
|
126
|
+
const count = firstBigrams.has(bigram) ? firstBigrams.get(bigram) : 0;
|
|
127
|
+
|
|
128
|
+
if (count > 0) {
|
|
129
|
+
firstBigrams.set(bigram, count - 1);
|
|
130
|
+
intersectionSize++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return (2.0 * intersectionSize) / (first.length + second.length - 2);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const substringAfter = (str: string, toFind: string) => {
|
|
138
|
+
const index = str.indexOf(toFind);
|
|
139
|
+
return index === -1 ? '' : str.substring(index + toFind.length);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const substringBefore = (str: string, toFind: string) => {
|
|
143
|
+
const index = str.indexOf(toFind);
|
|
144
|
+
return index === -1 ? '' : str.substring(0, index);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export const substringAfterLast = (str: string, toFind: string) => {
|
|
148
|
+
const index = str.lastIndexOf(toFind);
|
|
149
|
+
return index === -1 ? '' : str.substring(index + toFind.length);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const substringBeforeLast = (str: string, toFind: string) => {
|
|
153
|
+
const index = str.lastIndexOf(toFind);
|
|
154
|
+
return index === -1 ? '' : str.substring(0, index);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// const generateHash = async (url: string) => {
|
|
158
|
+
// let returnedBuffer;
|
|
159
|
+
|
|
160
|
+
// const response = await fetch(url);
|
|
161
|
+
// const arrayBuffer = await response.arrayBuffer();
|
|
162
|
+
// returnedBuffer = Buffer.from(arrayBuffer);
|
|
163
|
+
|
|
164
|
+
// // const { info, data } = await sharp(returnedBuffer).ensureAlpha().raw().toBuffer({
|
|
165
|
+
// // resolveWithObject: true,
|
|
166
|
+
// // });
|
|
167
|
+
|
|
168
|
+
// return blurhash.encode(new Uint8ClampedArray(data), info.width, info.height, 4, 3);
|
|
169
|
+
// };
|
|
170
|
+
|
|
171
|
+
export const getHashFromImage = (url: string) => {
|
|
172
|
+
if (url?.length === 0) {
|
|
173
|
+
return '';
|
|
174
|
+
} else {
|
|
175
|
+
// let hash!: string;
|
|
176
|
+
// generateHash(url).then(hashKey => (hash = hashKey));
|
|
177
|
+
return 'hash';
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// Function to find similar titles
|
|
182
|
+
export function findSimilarTitles(inputTitle: string, titles: any[]): any[] {
|
|
183
|
+
const results: (any & { similarity: number })[] = [];
|
|
184
|
+
|
|
185
|
+
titles?.forEach((titleObj: any) => {
|
|
186
|
+
const title = cleanTitle(
|
|
187
|
+
titleObj?.title
|
|
188
|
+
?.toLowerCase()
|
|
189
|
+
?.replace(/\([^\)]*\)/g, '')
|
|
190
|
+
.trim() || ''
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
// Calculate similarity score between inputTitle and title
|
|
194
|
+
const similarity = compareTwoStrings(cleanTitle(inputTitle?.toLowerCase() || ''), title);
|
|
195
|
+
|
|
196
|
+
if (similarity > 0.6) {
|
|
197
|
+
results.push({ ...titleObj, similarity });
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const isSubAvailable = results.some((result) => result.episodes && result.episodes.sub > 0);
|
|
202
|
+
|
|
203
|
+
// If episodes.sub is available, sort the results
|
|
204
|
+
if (isSubAvailable) {
|
|
205
|
+
return results.sort((a, b) => {
|
|
206
|
+
// First sort by similarity in descending order
|
|
207
|
+
if (b.similarity !== a.similarity) {
|
|
208
|
+
return b.similarity - a.similarity;
|
|
209
|
+
}
|
|
210
|
+
// If similarity is the same, sort by episodes.sub in descending order
|
|
211
|
+
return (b.episodes?.sub || 0) - (a.episodes?.sub || 0);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// If episodes.sub is not available, return the original list
|
|
216
|
+
return results.sort((a, b) => b.similarity - a.similarity);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Function to convert Roman numerals to Arabic numbers
|
|
220
|
+
function romanToArabic(roman: string): number {
|
|
221
|
+
const romanMap: Record<string, number> = {
|
|
222
|
+
i: 1,
|
|
223
|
+
v: 5,
|
|
224
|
+
x: 10,
|
|
225
|
+
l: 50,
|
|
226
|
+
c: 100,
|
|
227
|
+
d: 500,
|
|
228
|
+
m: 1000,
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
roman = roman.toLowerCase();
|
|
232
|
+
let result = 0;
|
|
233
|
+
|
|
234
|
+
for (let i = 0; i < roman.length; i++) {
|
|
235
|
+
const current = romanMap[roman[i]!]!;
|
|
236
|
+
const next = romanMap[roman[i + 1]!];
|
|
237
|
+
|
|
238
|
+
if (next && current < next) {
|
|
239
|
+
result += next - current;
|
|
240
|
+
i++;
|
|
241
|
+
} else {
|
|
242
|
+
result += current;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function cleanTitle(title: string | undefined | null): string {
|
|
250
|
+
if (!title) return '';
|
|
251
|
+
|
|
252
|
+
return transformSpecificVariations(
|
|
253
|
+
removeSpecialChars(
|
|
254
|
+
title
|
|
255
|
+
.replace(/[^A-Za-z0-9!@#$%^&*() ]/gim, ' ')
|
|
256
|
+
.replace(/(th|rd|nd|st) (Season|season)/gim, '')
|
|
257
|
+
.replace(/\([^\(]*\)$/gim, '')
|
|
258
|
+
.replace(/season/g, '')
|
|
259
|
+
.replace(/\b(IX|IV|V?I{0,3})\b/gi, (match: any) => romanToArabic(match).toString())
|
|
260
|
+
.replace(/ {2}/g, ' ')
|
|
261
|
+
.replace(/"/g, '')
|
|
262
|
+
.trimEnd()
|
|
263
|
+
)
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function removeSpecialChars(title: string | undefined | null): string {
|
|
268
|
+
if (!title) return '';
|
|
269
|
+
|
|
270
|
+
return title
|
|
271
|
+
.replace(/[^A-Za-z0-9!@#$%^&*()\-= ]/gim, ' ')
|
|
272
|
+
.replace(/[^A-Za-z0-9\-= ]/gim, '')
|
|
273
|
+
.replace(/ {2}/g, ' ');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function transformSpecificVariations(title: string | undefined | null): string {
|
|
277
|
+
if (!title) return '';
|
|
278
|
+
|
|
279
|
+
return title.replace(/yuu/g, 'yu').replace(/ ou/g, ' oh');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function sanitizeTitle(title: string): string {
|
|
283
|
+
let resTitle = title.replace(/ *(\(dub\)|\(sub\)|\(uncensored\)|\(uncut\)|\(subbed\)|\(dubbed\))/i, '');
|
|
284
|
+
resTitle = resTitle.replace(/ *\([^)]+audio\)/i, '');
|
|
285
|
+
resTitle = resTitle.replace(/ BD( |$)/i, '');
|
|
286
|
+
resTitle = resTitle.replace(/\(TV\)/g, '');
|
|
287
|
+
resTitle = resTitle.trim();
|
|
288
|
+
resTitle = resTitle.substring(0, 99); // truncate
|
|
289
|
+
return resTitle;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function stringSearch(string: string, pattern: string): number {
|
|
293
|
+
let count = 0;
|
|
294
|
+
string = string.toLowerCase();
|
|
295
|
+
pattern = pattern.toLowerCase();
|
|
296
|
+
string = string.replace(/[^a-zA-Z0-9 -]/g, '');
|
|
297
|
+
pattern = pattern.replace(/[^a-zA-Z0-9 -]/g, '');
|
|
298
|
+
|
|
299
|
+
for (let i = 0; i < string.length; i++) {
|
|
300
|
+
for (let j = 0; j < pattern.length; j++) {
|
|
301
|
+
if (pattern[j] !== string[i + j]) break;
|
|
302
|
+
if (j === pattern.length - 1) count++;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return count;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
interface FilterOptions {
|
|
309
|
+
timeout?: number;
|
|
310
|
+
headers?: Record<string, string>;
|
|
311
|
+
indicators?: string[];
|
|
312
|
+
concurrency?: number;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export const filterValidM3U8 = async (m3u8Links: string[], options: FilterOptions = {}): Promise<string[]> => {
|
|
316
|
+
const {
|
|
317
|
+
timeout = 10000,
|
|
318
|
+
headers = {},
|
|
319
|
+
indicators = ['#EXT', '#EXTINF', '#EXT-X-', '#EXTM3U'],
|
|
320
|
+
concurrency = 10,
|
|
321
|
+
} = options;
|
|
322
|
+
|
|
323
|
+
const validLinks: string[] = [];
|
|
324
|
+
let index = 0;
|
|
325
|
+
|
|
326
|
+
const next = async (): Promise<void> => {
|
|
327
|
+
while (index < m3u8Links.length) {
|
|
328
|
+
const currentIndex = index++;
|
|
329
|
+
const url = m3u8Links[currentIndex]!;
|
|
330
|
+
|
|
331
|
+
const controller = new AbortController();
|
|
332
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
333
|
+
|
|
334
|
+
try {
|
|
335
|
+
const response = await fetch(url, {
|
|
336
|
+
headers: {
|
|
337
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
|
338
|
+
...headers,
|
|
339
|
+
},
|
|
340
|
+
signal: controller.signal,
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
clearTimeout(timeoutId);
|
|
344
|
+
|
|
345
|
+
if (!response.ok) {
|
|
346
|
+
// console.warn(`❌ HTTP error (${response.status}) for ${url}`);
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// Optional shortcut: skip non-M3U8 content types
|
|
351
|
+
const contentType = response.headers.get('content-type');
|
|
352
|
+
if (contentType && !contentType.includes('application/vnd.apple.mpegurl') && !contentType.includes('mpegurl')) {
|
|
353
|
+
// console.info(`⚠️ Skipping non-M3U8 type: ${url}`);
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const content = await response.text();
|
|
358
|
+
if (indicators.some((ind) => content.includes(ind))) {
|
|
359
|
+
validLinks.push(url);
|
|
360
|
+
} else {
|
|
361
|
+
// console.info(`⚠️ No M3U8 indicators found in: ${url}`);
|
|
362
|
+
}
|
|
363
|
+
} catch (err: any) {
|
|
364
|
+
clearTimeout(timeoutId);
|
|
365
|
+
const reason = err.name === 'AbortError' ? 'timeout' : err.message;
|
|
366
|
+
// console.warn(`⚠️ Failed to validate M3U8 (${url}): ${reason}`);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// Run N concurrent validators
|
|
372
|
+
await Promise.all(Array.from({ length: concurrency }, () => next()));
|
|
373
|
+
return validLinks;
|
|
374
|
+
};
|