react-native-consumet 0.4.3 → 0.5.0
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/src/main/java/com/consumet/ConsumetModule.kt +3 -3
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/index.js.map +1 -1
- package/lib/commonjs/models/proxy.js +80 -25
- package/lib/commonjs/models/proxy.js.map +1 -1
- package/lib/commonjs/models/types.js.map +1 -1
- package/lib/commonjs/providers/anime/animekai.js +19 -14
- package/lib/commonjs/providers/anime/animekai.js.map +1 -1
- package/lib/commonjs/providers/anime/zoro.js +26 -19
- package/lib/commonjs/providers/anime/zoro.js.map +1 -1
- package/lib/commonjs/providers/meta/anilist.js +38 -208
- package/lib/commonjs/providers/meta/anilist.js.map +1 -1
- package/lib/commonjs/providers/meta/mal.js +4 -4
- package/lib/commonjs/providers/meta/mal.js.map +1 -1
- package/lib/commonjs/providers/meta/tmdb.js +4 -14
- package/lib/commonjs/providers/meta/tmdb.js.map +1 -1
- package/lib/commonjs/providers/movies/multimovies.js +16 -8
- package/lib/commonjs/providers/movies/multimovies.js.map +1 -1
- package/lib/commonjs/utils/index.js +4 -4
- package/lib/commonjs/utils/utils.js +140 -4
- package/lib/commonjs/utils/utils.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/index.js.map +1 -1
- package/lib/module/models/proxy.js +80 -25
- package/lib/module/models/proxy.js.map +1 -1
- package/lib/module/models/types.js.map +1 -1
- package/lib/module/providers/anime/animekai.js +18 -14
- package/lib/module/providers/anime/animekai.js.map +1 -1
- package/lib/module/providers/anime/zoro.js +25 -19
- package/lib/module/providers/anime/zoro.js.map +1 -1
- package/lib/module/providers/meta/anilist.js +39 -209
- package/lib/module/providers/meta/anilist.js.map +1 -1
- package/lib/module/providers/meta/mal.js +5 -5
- package/lib/module/providers/meta/mal.js.map +1 -1
- package/lib/module/providers/meta/tmdb.js +5 -15
- package/lib/module/providers/meta/tmdb.js.map +1 -1
- package/lib/module/providers/movies/multimovies.js +16 -8
- package/lib/module/providers/movies/multimovies.js.map +1 -1
- package/lib/module/utils/index.js +2 -2
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/utils.js +126 -1
- package/lib/module/utils/utils.js.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +3 -2
- package/lib/typescript/commonjs/src/index.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/proxy.d.ts +6 -7
- package/lib/typescript/commonjs/src/models/proxy.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/types.d.ts +4 -1
- package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/animekai.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/anime/zoro.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts +0 -3
- package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/meta/tmdb.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/movies/multimovies.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/utils.d.ts +15 -1
- package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +3 -2
- package/lib/typescript/module/src/index.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/proxy.d.ts +6 -7
- package/lib/typescript/module/src/models/proxy.d.ts.map +1 -1
- package/lib/typescript/module/src/models/types.d.ts +4 -1
- package/lib/typescript/module/src/models/types.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/animekai.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/anime/zoro.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/meta/anilist.d.ts +0 -3
- package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/meta/tmdb.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/movies/multimovies.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/index.d.ts +2 -2
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/utils.d.ts +15 -1
- package/lib/typescript/module/src/utils/utils.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/index.tsx +3 -0
- package/src/models/index.ts +2 -0
- package/src/models/proxy.ts +80 -30
- package/src/models/types.ts +6 -1
- package/src/providers/anime/animekai.ts +17 -14
- package/src/providers/anime/zoro.ts +25 -20
- package/src/providers/meta/anilist.ts +71 -324
- package/src/providers/meta/mal.ts +5 -5
- package/src/providers/meta/tmdb.ts +5 -15
- package/src/providers/movies/multimovies.ts +15 -11
- package/src/utils/index.ts +2 -2
- package/src/utils/utils.ts +162 -1
package/src/utils/utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { compareTwoStrings } from 'string-similarity';
|
|
1
2
|
// import sharp from 'sharp';
|
|
2
3
|
import { load } from 'cheerio';
|
|
3
4
|
// import * as blurhash from 'blurhash';
|
|
@@ -104,7 +105,7 @@ export function convertDuration(milliseconds: number) {
|
|
|
104
105
|
return `PT${hours}H${minutes}M${seconds}S`;
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
export const
|
|
108
|
+
export const calculateStringSimilarity = (first: string, second: string): number => {
|
|
108
109
|
first = first.replace(/\s+/g, '');
|
|
109
110
|
second = second.replace(/\s+/g, '');
|
|
110
111
|
|
|
@@ -176,3 +177,163 @@ export const getHashFromImage = (url: string) => {
|
|
|
176
177
|
return 'hash';
|
|
177
178
|
}
|
|
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
|
+
.replaceAll(/[^A-Za-z0-9!@#$%^&*() ]/gim, ' ')
|
|
256
|
+
.replaceAll(/(th|rd|nd|st) (Season|season)/gim, '')
|
|
257
|
+
.replaceAll(/\([^\(]*\)$/gim, '')
|
|
258
|
+
.replaceAll('season', '')
|
|
259
|
+
.replaceAll(/\b(IX|IV|V?I{0,3})\b/gi, (match) => romanToArabic(match).toString())
|
|
260
|
+
.replaceAll(' ', ' ')
|
|
261
|
+
.replaceAll('"', '')
|
|
262
|
+
.trimEnd()
|
|
263
|
+
)
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function removeSpecialChars(title: string | undefined | null): string {
|
|
268
|
+
if (!title) return '';
|
|
269
|
+
|
|
270
|
+
return title
|
|
271
|
+
.replaceAll(/[^A-Za-z0-9!@#$%^&*()\-= ]/gim, ' ')
|
|
272
|
+
.replaceAll(/[^A-Za-z0-9\-= ]/gim, '')
|
|
273
|
+
.replaceAll(' ', ' ');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export function transformSpecificVariations(title: string | undefined | null): string {
|
|
277
|
+
if (!title) return '';
|
|
278
|
+
|
|
279
|
+
return title.replaceAll('yuu', 'yu').replaceAll(' ou', ' 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
|
+
export function parseUrl(url: string): {
|
|
309
|
+
href: string;
|
|
310
|
+
origin: string;
|
|
311
|
+
pathname: string;
|
|
312
|
+
hostname: string;
|
|
313
|
+
search: string;
|
|
314
|
+
hash: string;
|
|
315
|
+
} {
|
|
316
|
+
// Simple URL parser for React Native
|
|
317
|
+
try {
|
|
318
|
+
const match = url.match(/^(https?:\/\/[^\/]+)(\/[^?#]*)?(\?[^#]*)?(#.*)?$/);
|
|
319
|
+
if (!match) throw new Error(`Invalid URL: ${url}`);
|
|
320
|
+
|
|
321
|
+
const origin = match[1] || '';
|
|
322
|
+
const pathname = match[2] || '/';
|
|
323
|
+
const search = match[3] || '';
|
|
324
|
+
const hash = match[4] || '';
|
|
325
|
+
|
|
326
|
+
return {
|
|
327
|
+
href: url,
|
|
328
|
+
origin,
|
|
329
|
+
pathname,
|
|
330
|
+
hostname: origin.replace(/^https?:\/\//, ''),
|
|
331
|
+
search,
|
|
332
|
+
hash,
|
|
333
|
+
};
|
|
334
|
+
} catch (e) {
|
|
335
|
+
console.error(`Error parsing URL: ${url}`, e);
|
|
336
|
+
// Return a minimal object with href to prevent crashes
|
|
337
|
+
return { href: url, origin: '', pathname: '', hostname: '', search: '', hash: '' };
|
|
338
|
+
}
|
|
339
|
+
}
|