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.
Files changed (93) hide show
  1. package/android/src/main/java/com/consumet/ConsumetModule.kt +3 -3
  2. package/lib/commonjs/index.js +1 -0
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/models/index.js.map +1 -1
  5. package/lib/commonjs/models/proxy.js +80 -25
  6. package/lib/commonjs/models/proxy.js.map +1 -1
  7. package/lib/commonjs/models/types.js.map +1 -1
  8. package/lib/commonjs/providers/anime/animekai.js +19 -14
  9. package/lib/commonjs/providers/anime/animekai.js.map +1 -1
  10. package/lib/commonjs/providers/anime/zoro.js +26 -19
  11. package/lib/commonjs/providers/anime/zoro.js.map +1 -1
  12. package/lib/commonjs/providers/meta/anilist.js +38 -208
  13. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  14. package/lib/commonjs/providers/meta/mal.js +4 -4
  15. package/lib/commonjs/providers/meta/mal.js.map +1 -1
  16. package/lib/commonjs/providers/meta/tmdb.js +4 -14
  17. package/lib/commonjs/providers/meta/tmdb.js.map +1 -1
  18. package/lib/commonjs/providers/movies/multimovies.js +16 -8
  19. package/lib/commonjs/providers/movies/multimovies.js.map +1 -1
  20. package/lib/commonjs/utils/index.js +4 -4
  21. package/lib/commonjs/utils/utils.js +140 -4
  22. package/lib/commonjs/utils/utils.js.map +1 -1
  23. package/lib/module/index.js +1 -0
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/models/index.js.map +1 -1
  26. package/lib/module/models/proxy.js +80 -25
  27. package/lib/module/models/proxy.js.map +1 -1
  28. package/lib/module/models/types.js.map +1 -1
  29. package/lib/module/providers/anime/animekai.js +18 -14
  30. package/lib/module/providers/anime/animekai.js.map +1 -1
  31. package/lib/module/providers/anime/zoro.js +25 -19
  32. package/lib/module/providers/anime/zoro.js.map +1 -1
  33. package/lib/module/providers/meta/anilist.js +39 -209
  34. package/lib/module/providers/meta/anilist.js.map +1 -1
  35. package/lib/module/providers/meta/mal.js +5 -5
  36. package/lib/module/providers/meta/mal.js.map +1 -1
  37. package/lib/module/providers/meta/tmdb.js +5 -15
  38. package/lib/module/providers/meta/tmdb.js.map +1 -1
  39. package/lib/module/providers/movies/multimovies.js +16 -8
  40. package/lib/module/providers/movies/multimovies.js.map +1 -1
  41. package/lib/module/utils/index.js +2 -2
  42. package/lib/module/utils/index.js.map +1 -1
  43. package/lib/module/utils/utils.js +126 -1
  44. package/lib/module/utils/utils.js.map +1 -1
  45. package/lib/typescript/commonjs/src/index.d.ts +3 -2
  46. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/src/models/index.d.ts +2 -2
  48. package/lib/typescript/commonjs/src/models/index.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/src/models/proxy.d.ts +6 -7
  50. package/lib/typescript/commonjs/src/models/proxy.d.ts.map +1 -1
  51. package/lib/typescript/commonjs/src/models/types.d.ts +4 -1
  52. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/src/providers/anime/animekai.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/src/providers/anime/zoro.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts +0 -3
  56. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  57. package/lib/typescript/commonjs/src/providers/meta/tmdb.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/src/providers/movies/multimovies.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/src/utils/index.d.ts +2 -2
  60. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  61. package/lib/typescript/commonjs/src/utils/utils.d.ts +15 -1
  62. package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -1
  63. package/lib/typescript/module/src/index.d.ts +3 -2
  64. package/lib/typescript/module/src/index.d.ts.map +1 -1
  65. package/lib/typescript/module/src/models/index.d.ts +2 -2
  66. package/lib/typescript/module/src/models/index.d.ts.map +1 -1
  67. package/lib/typescript/module/src/models/proxy.d.ts +6 -7
  68. package/lib/typescript/module/src/models/proxy.d.ts.map +1 -1
  69. package/lib/typescript/module/src/models/types.d.ts +4 -1
  70. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  71. package/lib/typescript/module/src/providers/anime/animekai.d.ts.map +1 -1
  72. package/lib/typescript/module/src/providers/anime/zoro.d.ts.map +1 -1
  73. package/lib/typescript/module/src/providers/meta/anilist.d.ts +0 -3
  74. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  75. package/lib/typescript/module/src/providers/meta/tmdb.d.ts.map +1 -1
  76. package/lib/typescript/module/src/providers/movies/multimovies.d.ts.map +1 -1
  77. package/lib/typescript/module/src/utils/index.d.ts +2 -2
  78. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  79. package/lib/typescript/module/src/utils/utils.d.ts +15 -1
  80. package/lib/typescript/module/src/utils/utils.d.ts.map +1 -1
  81. package/package.json +5 -2
  82. package/src/index.tsx +3 -0
  83. package/src/models/index.ts +2 -0
  84. package/src/models/proxy.ts +80 -30
  85. package/src/models/types.ts +6 -1
  86. package/src/providers/anime/animekai.ts +17 -14
  87. package/src/providers/anime/zoro.ts +25 -20
  88. package/src/providers/meta/anilist.ts +71 -324
  89. package/src/providers/meta/mal.ts +5 -5
  90. package/src/providers/meta/tmdb.ts +5 -15
  91. package/src/providers/movies/multimovies.ts +15 -11
  92. package/src/utils/index.ts +2 -2
  93. package/src/utils/utils.ts +162 -1
@@ -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 compareTwoStrings = (first: string, second: string): number => {
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
+ }