react-native-consumet 0.4.3 → 0.6.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 (119) hide show
  1. package/android/build.gradle +1 -0
  2. package/android/generated/java/com/consumet/NativeConsumetSpec.java +8 -0
  3. package/android/generated/jni/RNConsumetSpec-generated.cpp +12 -0
  4. package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI-generated.cpp +14 -0
  5. package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI.h +18 -0
  6. package/android/src/main/java/com/consumet/ConsumetModule.kt +63 -38
  7. package/android/src/main/java/com/consumet/DdosGuardModule.kt +142 -0
  8. package/ios/generated/RNConsumetSpec/RNConsumetSpec-generated.mm +14 -0
  9. package/ios/generated/RNConsumetSpec/RNConsumetSpec.h +6 -0
  10. package/ios/generated/RNConsumetSpecJSI-generated.cpp +14 -0
  11. package/ios/generated/RNConsumetSpecJSI.h +18 -0
  12. package/lib/commonjs/NativeConsumet.ts +2 -0
  13. package/lib/commonjs/index.js +10 -4
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/models/index.js.map +1 -1
  16. package/lib/commonjs/models/proxy.js +80 -25
  17. package/lib/commonjs/models/proxy.js.map +1 -1
  18. package/lib/commonjs/models/types.js.map +1 -1
  19. package/lib/commonjs/providers/anime/animekai.js +19 -14
  20. package/lib/commonjs/providers/anime/animekai.js.map +1 -1
  21. package/lib/commonjs/providers/anime/animepahe.js +59 -9
  22. package/lib/commonjs/providers/anime/animepahe.js.map +1 -1
  23. package/lib/commonjs/providers/anime/zoro.js +26 -19
  24. package/lib/commonjs/providers/anime/zoro.js.map +1 -1
  25. package/lib/commonjs/providers/meta/anilist.js +38 -208
  26. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  27. package/lib/commonjs/providers/meta/mal.js +4 -4
  28. package/lib/commonjs/providers/meta/mal.js.map +1 -1
  29. package/lib/commonjs/providers/meta/tmdb.js +6 -15
  30. package/lib/commonjs/providers/meta/tmdb.js.map +1 -1
  31. package/lib/commonjs/providers/movies/multimovies.js +33 -13
  32. package/lib/commonjs/providers/movies/multimovies.js.map +1 -1
  33. package/lib/commonjs/utils/index.js +4 -4
  34. package/lib/commonjs/utils/utils.js +140 -4
  35. package/lib/commonjs/utils/utils.js.map +1 -1
  36. package/lib/module/NativeConsumet.ts +2 -0
  37. package/lib/module/index.js +6 -3
  38. package/lib/module/index.js.map +1 -1
  39. package/lib/module/models/index.js.map +1 -1
  40. package/lib/module/models/proxy.js +80 -25
  41. package/lib/module/models/proxy.js.map +1 -1
  42. package/lib/module/models/types.js.map +1 -1
  43. package/lib/module/providers/anime/animekai.js +18 -14
  44. package/lib/module/providers/anime/animekai.js.map +1 -1
  45. package/lib/module/providers/anime/animepahe.js +60 -10
  46. package/lib/module/providers/anime/animepahe.js.map +1 -1
  47. package/lib/module/providers/anime/zoro.js +25 -19
  48. package/lib/module/providers/anime/zoro.js.map +1 -1
  49. package/lib/module/providers/meta/anilist.js +39 -209
  50. package/lib/module/providers/meta/anilist.js.map +1 -1
  51. package/lib/module/providers/meta/mal.js +5 -5
  52. package/lib/module/providers/meta/mal.js.map +1 -1
  53. package/lib/module/providers/meta/tmdb.js +7 -16
  54. package/lib/module/providers/meta/tmdb.js.map +1 -1
  55. package/lib/module/providers/movies/multimovies.js +33 -13
  56. package/lib/module/providers/movies/multimovies.js.map +1 -1
  57. package/lib/module/utils/index.js +2 -2
  58. package/lib/module/utils/index.js.map +1 -1
  59. package/lib/module/utils/utils.js +126 -1
  60. package/lib/module/utils/utils.js.map +1 -1
  61. package/lib/typescript/commonjs/src/NativeConsumet.d.ts +4 -0
  62. package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
  63. package/lib/typescript/commonjs/src/index.d.ts +6 -3
  64. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  65. package/lib/typescript/commonjs/src/models/index.d.ts +2 -2
  66. package/lib/typescript/commonjs/src/models/index.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/src/models/proxy.d.ts +6 -7
  68. package/lib/typescript/commonjs/src/models/proxy.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/src/models/types.d.ts +4 -1
  70. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/src/providers/anime/animekai.d.ts.map +1 -1
  72. package/lib/typescript/commonjs/src/providers/anime/animepahe.d.ts +7 -3
  73. package/lib/typescript/commonjs/src/providers/anime/animepahe.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/src/providers/anime/zoro.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts +0 -3
  76. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/providers/meta/tmdb.d.ts.map +1 -1
  78. package/lib/typescript/commonjs/src/providers/movies/multimovies.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/utils/index.d.ts +2 -2
  80. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/utils/utils.d.ts +15 -1
  82. package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -1
  83. package/lib/typescript/module/src/NativeConsumet.d.ts +4 -0
  84. package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
  85. package/lib/typescript/module/src/index.d.ts +6 -3
  86. package/lib/typescript/module/src/index.d.ts.map +1 -1
  87. package/lib/typescript/module/src/models/index.d.ts +2 -2
  88. package/lib/typescript/module/src/models/index.d.ts.map +1 -1
  89. package/lib/typescript/module/src/models/proxy.d.ts +6 -7
  90. package/lib/typescript/module/src/models/proxy.d.ts.map +1 -1
  91. package/lib/typescript/module/src/models/types.d.ts +4 -1
  92. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  93. package/lib/typescript/module/src/providers/anime/animekai.d.ts.map +1 -1
  94. package/lib/typescript/module/src/providers/anime/animepahe.d.ts +7 -3
  95. package/lib/typescript/module/src/providers/anime/animepahe.d.ts.map +1 -1
  96. package/lib/typescript/module/src/providers/anime/zoro.d.ts.map +1 -1
  97. package/lib/typescript/module/src/providers/meta/anilist.d.ts +0 -3
  98. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  99. package/lib/typescript/module/src/providers/meta/tmdb.d.ts.map +1 -1
  100. package/lib/typescript/module/src/providers/movies/multimovies.d.ts.map +1 -1
  101. package/lib/typescript/module/src/utils/index.d.ts +2 -2
  102. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  103. package/lib/typescript/module/src/utils/utils.d.ts +15 -1
  104. package/lib/typescript/module/src/utils/utils.d.ts.map +1 -1
  105. package/package.json +5 -2
  106. package/src/NativeConsumet.ts +2 -0
  107. package/src/index.tsx +5 -3
  108. package/src/models/index.ts +2 -0
  109. package/src/models/proxy.ts +80 -30
  110. package/src/models/types.ts +6 -1
  111. package/src/providers/anime/animekai.ts +17 -14
  112. package/src/providers/anime/animepahe.ts +70 -10
  113. package/src/providers/anime/zoro.ts +25 -20
  114. package/src/providers/meta/anilist.ts +71 -325
  115. package/src/providers/meta/mal.ts +5 -5
  116. package/src/providers/meta/tmdb.ts +7 -16
  117. package/src/providers/movies/multimovies.ts +28 -19
  118. package/src/utils/index.ts +2 -2
  119. package/src/utils/utils.ts +162 -1
@@ -17,10 +17,11 @@ import {
17
17
 
18
18
  import { StreamSB, MegaCloud, StreamTape } from '../../utils';
19
19
  import { USER_AGENT } from '../../utils';
20
+ import axios from 'axios';
20
21
 
21
22
  class Zoro extends AnimeParser {
22
23
  override readonly name = 'Zoro';
23
- protected override baseUrl = 'https://hianimez.to';
24
+ protected override baseUrl = 'https://hianime.nz';
24
25
  protected override logo =
25
26
  'https://is3-ssl.mzstatic.com/image/thumb/Purple112/v4/7e/91/00/7e9100ee-2b62-0942-4cdc-e9b93252ce1c/source/512x512bb.jpg';
26
27
  protected override classPath = 'ANIME.Zoro';
@@ -536,7 +537,7 @@ class Zoro extends AnimeParser {
536
537
  title: '',
537
538
  };
538
539
  try {
539
- const { data } = await this.client.get(`${this.baseUrl}/watch/${id}`);
540
+ const { data } = await axios.get(`${this.baseUrl}/watch/${id}`);
540
541
  const $ = load(data);
541
542
 
542
543
  const { mal_id, anilist_id } = JSON.parse($('#syncData').text());
@@ -583,7 +584,7 @@ class Zoro extends AnimeParser {
583
584
  }
584
585
 
585
586
  // ZORO - PAGE INFO
586
- const zInfo = await this.client.get(info.url);
587
+ const zInfo = await axios.get(info.url);
587
588
  const $$$ = load(zInfo.data);
588
589
 
589
590
  info.genres = [];
@@ -623,34 +624,36 @@ class Zoro extends AnimeParser {
623
624
  .trim();
624
625
  }
625
626
 
626
- const episodesAjax = await this.client.get(`${this.baseUrl}/ajax/v2/episode/list/${id.split('-').pop()}`, {
627
+ const episodesAjax = await axios.get(`${this.baseUrl}/ajax/v2/episode/list/${id.split('-').pop()}`, {
627
628
  headers: {
628
629
  'X-Requested-With': 'XMLHttpRequest',
629
630
  'Referer': `${this.baseUrl}/watch/${id}`,
630
631
  },
631
632
  });
632
-
633
633
  const $$ = load(episodesAjax.data.html);
634
634
 
635
- info.totalEpisodes = $$('div.detail-infor-content > div > a').length;
635
+ // Pre-calculate values used for all episodes
636
+ const episodeElements = $$('div.detail-infor-content > div > a');
637
+ const subCount = parseInt($('div.film-stats div.tick div.tick-item.tick-sub').text().trim()) || 0;
638
+ const dubCount = parseInt($('div.film-stats div.tick div.tick-item.tick-dub').text().trim()) || 0;
639
+
640
+ info.totalEpisodes = episodeElements.length;
636
641
  info.episodes = [];
637
- $$('div.detail-infor-content > div > a').each((i, el) => {
638
- const episodeId = $$(el).attr('href')?.split('/')[2]?.replace('?ep=', '$episode$')!;
639
- const number = parseInt($$(el).attr('data-number')!);
640
- const title = $$(el).attr('title');
641
- const url = this.baseUrl + $$(el).attr('href');
642
- const isFiller = $$(el).hasClass('ssl-item-filler');
643
- const isSubbed = number <= (parseInt($('div.film-stats div.tick div.tick-item.tick-sub').text().trim()) || 0);
644
- const isDubbed = number <= (parseInt($('div.film-stats div.tick div.tick-item.tick-dub').text().trim()) || 0);
642
+
643
+ // Single pass through episodes
644
+ episodeElements.each((i, el) => {
645
+ const $el = $$(el);
646
+ const href = $el.attr('href') || '';
647
+ const number = parseInt($el.attr('data-number') || '0');
645
648
 
646
649
  info.episodes?.push({
647
- id: episodeId,
650
+ id: href.split('/')[2]?.replace('?ep=', '$episode$') || '',
648
651
  number: number,
649
- title: title,
650
- isFiller: isFiller,
651
- isSubbed: isSubbed,
652
- isDubbed: isDubbed,
653
- url: url,
652
+ title: $el.attr('title'),
653
+ isFiller: $el.hasClass('ssl-item-filler'),
654
+ isSubbed: number <= subCount,
655
+ isDubbed: number <= dubCount,
656
+ url: this.baseUrl + href,
654
657
  });
655
658
  });
656
659
 
@@ -828,6 +831,7 @@ class Zoro extends AnimeParser {
828
831
  }
829
832
  return res;
830
833
  } catch (err) {
834
+ console.log(err);
831
835
  throw new Error('Something went wrong. Please try again later.');
832
836
  }
833
837
  };
@@ -867,6 +871,7 @@ class Zoro extends AnimeParser {
867
871
  });
868
872
  return results;
869
873
  } catch (err) {
874
+ console.log(err);
870
875
  throw new Error('Something went wrong. Please try again later.');
871
876
  }
872
877
  };
@@ -18,6 +18,7 @@ import {
18
18
  type ProxyConfig,
19
19
  type ITitle,
20
20
  type IStaff,
21
+ type AniZipEpisode,
21
22
  } from '../../models';
22
23
  import {
23
24
  anilistSearchQuery,
@@ -39,9 +40,7 @@ import Zoro from '../anime/zoro';
39
40
  import AnimeKai from '../anime/animekai';
40
41
  import AnimePahe from '../anime/animepahe';
41
42
  import Mangasee123 from '../manga/mangasee123';
42
- import Bilibili from '../anime/bilibili';
43
- import { ANIFY_URL, compareTwoStrings, getHashFromImage } from '../../utils/utils';
44
- import type { AniZipEpisode } from '../../models/types';
43
+ import { ANIFY_URL, findSimilarTitles, getHashFromImage } from '../../utils/utils';
45
44
 
46
45
  class Anilist extends AnimeParser {
47
46
  override readonly name = 'Anilist';
@@ -578,18 +577,15 @@ class Anilist extends AnimeParser {
578
577
  airDate: item.airDate ?? null,
579
578
  }));
580
579
  if (!animeInfo.episodes?.length) {
581
- animeInfo.episodes = await this.fetchDefaultEpisodeList(
582
- {
583
- idMal: animeInfo.malId! as number,
584
- season: data.data.Media.season,
585
- startDate: { year: parseInt(animeInfo.releaseDate!) },
586
- title: {
587
- english: animeInfo.title?.english!,
588
- romaji: animeInfo.title?.romaji!,
589
- },
580
+ animeInfo.episodes = await this.fetchDefaultEpisodeList({
581
+ idMal: animeInfo.malId! as number,
582
+ season: data.data.Media.season,
583
+ startDate: { year: parseInt(animeInfo.releaseDate!) },
584
+ title: {
585
+ english: animeInfo.title?.english!,
586
+ romaji: animeInfo.title?.romaji!,
590
587
  },
591
- id
592
- );
588
+ });
593
589
  animeInfo.episodes = animeInfo.episodes?.map((episode: IAnimeEpisode) => {
594
590
  if (!episode.image) {
595
591
  episode.image = animeInfo.image;
@@ -600,18 +596,15 @@ class Anilist extends AnimeParser {
600
596
  });
601
597
  }
602
598
  } catch (err) {
603
- animeInfo.episodes = await this.fetchDefaultEpisodeList(
604
- {
605
- idMal: animeInfo.malId! as number,
606
- season: data.data.Media.season,
607
- startDate: { year: parseInt(animeInfo.releaseDate!) },
608
- title: {
609
- english: animeInfo.title?.english!,
610
- romaji: animeInfo.title?.romaji!,
611
- },
599
+ animeInfo.episodes = await this.fetchDefaultEpisodeList({
600
+ idMal: animeInfo.malId! as number,
601
+ season: data.data.Media.season,
602
+ startDate: { year: parseInt(animeInfo.releaseDate!) },
603
+ title: {
604
+ english: animeInfo.title?.english!,
605
+ romaji: animeInfo.title?.romaji!,
612
606
  },
613
- id
614
- );
607
+ });
615
608
 
616
609
  animeInfo.episodes = animeInfo.episodes?.map((episode: IAnimeEpisode) => {
617
610
  if (!episode.image) {
@@ -625,19 +618,16 @@ class Anilist extends AnimeParser {
625
618
  return animeInfo;
626
619
  }
627
620
  } else
628
- animeInfo.episodes = await this.fetchDefaultEpisodeList(
629
- {
630
- idMal: animeInfo.malId! as number,
631
- season: data.data.Media.season,
632
- startDate: { year: parseInt(animeInfo.releaseDate!) },
633
- title: {
634
- english: animeInfo.title?.english!,
635
- romaji: animeInfo.title?.romaji!,
636
- },
637
- externalLinks: data.data.Media.externalLinks.filter((link: any) => link.type === 'STREAMING'),
621
+ animeInfo.episodes = await this.fetchDefaultEpisodeList({
622
+ idMal: animeInfo.malId! as number,
623
+ season: data.data.Media.season,
624
+ startDate: { year: parseInt(animeInfo.releaseDate!) },
625
+ title: {
626
+ english: animeInfo.title?.english!,
627
+ romaji: animeInfo.title?.romaji!,
638
628
  },
639
- id
640
- );
629
+ externalLinks: data.data.Media.externalLinks.filter((link: any) => link.type === 'STREAMING'),
630
+ });
641
631
 
642
632
  if (fetchFiller) {
643
633
  const { data: fillerData } = await this.client.get(
@@ -701,239 +691,6 @@ class Anilist extends AnimeParser {
701
691
  }
702
692
  };
703
693
 
704
- private findAnime = async (
705
- title: { romaji: string; english: string },
706
- season: string,
707
- startDate: number,
708
- malId: number,
709
- anilistId: string,
710
- externalLinks?: any
711
- ): Promise<IAnimeEpisode[]> => {
712
- title.english = title.english ?? title.romaji;
713
- title.romaji = title.romaji ?? title.english;
714
-
715
- title.english = title.english.toLowerCase();
716
- title.romaji = title.romaji.toLowerCase();
717
-
718
- if (title.english === title.romaji) {
719
- // console.log(
720
- // 'findAnime',
721
- // await this.findAnimeSlug(title.english, season, startDate, malId, anilistId, externalLinks)
722
- // );
723
- return (await this.findAnimeSlug(title.english, season, startDate, malId, anilistId, externalLinks)) ?? [];
724
- }
725
-
726
- const romajiPossibleEpisodes = await this.findAnimeSlug(
727
- title.romaji,
728
- season,
729
- startDate,
730
- malId,
731
- anilistId,
732
- externalLinks
733
- );
734
-
735
- if (romajiPossibleEpisodes) {
736
- return romajiPossibleEpisodes;
737
- }
738
-
739
- const englishPossibleEpisodes = await this.findAnimeSlug(
740
- title.english,
741
- season,
742
- startDate,
743
- malId,
744
- anilistId,
745
- externalLinks
746
- );
747
- // console.log('romajiPossibleEpisodes', romajiPossibleEpisodes);
748
- // console.log('englishPossibleEpisodes', englishPossibleEpisodes);
749
- return englishPossibleEpisodes ?? [];
750
- };
751
-
752
- private findAnimeSlug = async (
753
- title: string,
754
- season: string,
755
- startDate: number,
756
- malId: number,
757
- anilistId: string,
758
- externalLinks?: any
759
- ): Promise<IAnimeEpisode[] | undefined> => {
760
- if (this.provider instanceof Anify) return (await this.provider.fetchAnimeInfo(anilistId)).episodes!;
761
-
762
- const slug = title.replace(/[^0-9a-zA-Z]+/g, ' ');
763
-
764
- let possibleAnime: any | undefined;
765
-
766
- if (malId && !(this.provider instanceof Bilibili)) {
767
- const malAsyncReq = await this.client.get(`${this.malSyncUrl}/mal/anime/${malId}`, {
768
- validateStatus: () => true,
769
- });
770
-
771
- if (malAsyncReq.status === 200) {
772
- const sitesT = malAsyncReq.data.Sites as {
773
- [k: string]: {
774
- [k: string]: { url: string; page: string; title: string };
775
- };
776
- };
777
- let sites = Object.values(sitesT).map((v, i) => {
778
- const obj: any = [...Object.values(Object.values(sitesT)[i]!)];
779
- const pages = obj.map((v: { page: string; url: string; title: string }) => ({
780
- page: v.page,
781
- url: v.url,
782
- title: v.title,
783
- }));
784
- return pages;
785
- }) as any[];
786
-
787
- sites = sites.flat();
788
-
789
- sites.sort((a, b) => {
790
- const targetTitle = malAsyncReq.data.title.toLowerCase();
791
-
792
- const firstRating = compareTwoStrings(targetTitle, a.title.toLowerCase());
793
- const secondRating = compareTwoStrings(targetTitle, b.title.toLowerCase());
794
-
795
- // Sort in descending order
796
- return secondRating - firstRating;
797
- });
798
-
799
- const possibleSource = sites.find((s) => {
800
- if (s.page.toLowerCase() === this.provider.name.toLowerCase()) return false;
801
- });
802
-
803
- if (possibleSource) {
804
- try {
805
- possibleAnime = await this.provider.fetchAnimeInfo(new URL(possibleSource.url).pathname.slice(1));
806
- } catch (err) {
807
- console.error(err);
808
- possibleAnime = await this.findAnimeRaw(slug);
809
- }
810
- } else possibleAnime = await this.findAnimeRaw(slug);
811
- } else possibleAnime = await this.findAnimeRaw(slug);
812
- } else possibleAnime = await this.findAnimeRaw(slug, externalLinks);
813
-
814
- if (!possibleAnime) return undefined;
815
-
816
- // // To avoid a new request, lets match and see if the anime show found is in sub/dub
817
-
818
- // const expectedType = dub ? SubOrSub.DUB : SubOrSub.SUB;
819
-
820
- // // Have this as a fallback in the meantime for compatibility
821
- // if (possibleAnime.subOrDub) {
822
- // if (possibleAnime.subOrDub !== SubOrSub.BOTH && possibleAnime.subOrDub !== expectedType) {
823
- // return undefined;
824
- // }
825
- // } else if ((!possibleAnime.hasDub && dub) || (!possibleAnime.hasSub && !dub)) {
826
- // return undefined;
827
- // }
828
-
829
- // if (this.provider instanceof Zoro) {
830
- // // Set the correct episode sub/dub request type
831
- // possibleAnime.episodes.forEach((_: any, index: number) => {
832
- // if (possibleAnime.subOrDub === SubOrSub.BOTH) {
833
- // possibleAnime.episodes[index].id = possibleAnime.episodes[index].id.replace(`$both`, dub ? '$dub' : '$sub');
834
- // }
835
- // });
836
- // }
837
-
838
- const possibleProviderEpisodes = possibleAnime.episodes as IAnimeEpisode[];
839
- // console.log('possibleProviderEpisodes', possibleProviderEpisodes);
840
- return possibleProviderEpisodes;
841
- // if (
842
- // typeof possibleProviderEpisodes[0]?.image !== 'undefined' &&
843
- // typeof possibleProviderEpisodes[0]?.title !== 'undefined' &&
844
- // typeof possibleProviderEpisodes[0]?.description !== 'undefined'
845
- // )
846
- // return possibleProviderEpisodes;
847
-
848
- // const options = {
849
- // headers: { 'Content-Type': 'application/json' },
850
- // query: kitsuSearchQuery(slug),
851
- // };
852
-
853
- // const newEpisodeList = await this.findKitsuAnime(possibleProviderEpisodes, options, season, startDate);
854
- // return newEpisodeList;
855
- };
856
-
857
- private findKitsuAnime = async (
858
- possibleProviderEpisodes: IAnimeEpisode[],
859
- options: {},
860
- season?: string,
861
- startDate?: number
862
- ) => {
863
- try {
864
- const kitsuEpisodes = await this.client.post(this.kitsuGraphqlUrl, options);
865
- const episodesList = new Map();
866
- if (kitsuEpisodes?.data.data) {
867
- const { nodes } = kitsuEpisodes.data.data.searchAnimeByTitle;
868
-
869
- if (nodes) {
870
- nodes.forEach((node: any) => {
871
- if (node.season === season && node.startDate.trim().split('-')[0] === startDate?.toString()) {
872
- const episodes = node.episodes.nodes;
873
-
874
- for (const episode of episodes) {
875
- const i = episode?.number.toString().replace(/"/g, '');
876
-
877
- let name;
878
- let description;
879
- let thumbnail;
880
-
881
- let thumbnailHash;
882
-
883
- if (episode?.description?.en)
884
- description = episode?.description.en.toString().replace(/"/g, '').replace('\\n', '\n');
885
- if (episode?.thumbnail) {
886
- thumbnail = episode?.thumbnail.original.url.toString().replace(/"/g, '');
887
- thumbnailHash = getHashFromImage(episode?.thumbnail.original.url.toString().replace(/"/g, ''));
888
- }
889
-
890
- if (episode) {
891
- if (episode.titles?.canonical) name = episode.titles.canonical.toString().replace(/"/g, '');
892
- episodesList.set(i, {
893
- episodeNum: episode?.number.toString().replace(/"/g, ''),
894
- title: name,
895
- description,
896
- createdAt: episode?.createdAt,
897
- thumbnail,
898
- });
899
- continue;
900
- }
901
- episodesList.set(i, {
902
- episodeNum: undefined,
903
- title: undefined,
904
- description: undefined,
905
- createdAt: undefined,
906
- thumbnail,
907
- thumbnailHash,
908
- });
909
- }
910
- }
911
- });
912
- }
913
- }
914
-
915
- const newEpisodeList: IAnimeEpisode[] = [];
916
- if (possibleProviderEpisodes?.length !== 0) {
917
- possibleProviderEpisodes?.forEach((ep: any, i: any) => {
918
- const j = (i + 1).toString();
919
- newEpisodeList.push({
920
- id: ep.id as string,
921
- title: ep.title ?? episodesList.get(j)?.title ?? null,
922
- image: ep.image ?? episodesList.get(j)?.thumbnail ?? null,
923
- imageHash: getHashFromImage(ep.image ?? episodesList.get(j)?.thumbnail ?? null),
924
- number: ep.number as number,
925
- createdAt: ep.createdAt ?? episodesList.get(j)?.createdAt ?? null,
926
- description: ep.description ?? episodesList.get(j)?.description ?? null,
927
- url: (ep.url as string) ?? null,
928
- });
929
- });
930
- }
931
- return newEpisodeList;
932
- } catch (error) {
933
- return possibleProviderEpisodes;
934
- }
935
- };
936
-
937
694
  /**
938
695
  * @param page page number to search for (optional)
939
696
  * @param perPage number of results per page (optional)
@@ -1221,48 +978,45 @@ class Anilist extends AnimeParser {
1221
978
  }
1222
979
  };
1223
980
 
1224
- private findAnimeRaw = async (slug: string, externalLinks?: any) => {
1225
- const findAnime = (await this.provider.search(slug)) as ISearch<IAnimeResult>;
1226
-
1227
- if (findAnime.results.length === 0) return undefined;
1228
-
1229
- // Sort the retrieved info for more accurate results.
981
+ private findAnimeRaw = async (title: ITitle) => {
982
+ const searchTerm = title?.romaji || title?.english || title?.userPreferred || '';
983
+ const findAnime = (await this.provider.search(searchTerm)) as ISearch<IAnimeResult>;
1230
984
 
1231
- let topRating = 0;
1232
-
1233
- findAnime.results.sort((a, b) => {
1234
- const targetTitle = slug.toLowerCase();
1235
-
1236
- let firstTitle: string;
1237
- let secondTitle: string;
985
+ if (!findAnime?.results) {
986
+ return {} as IAnimeEpisode[];
987
+ }
1238
988
 
1239
- if (typeof a.title === 'string') firstTitle = a.title as string;
1240
- else firstTitle = a.title.english ?? a.title.romaji ?? '';
989
+ // Run similar title searches in parallel
990
+ const [mappedEng, mappedRom] = await Promise.all([
991
+ Promise.resolve(findSimilarTitles(title?.english || '', findAnime.results)),
992
+ Promise.resolve(findSimilarTitles(title?.romaji || '', findAnime.results)),
993
+ ]);
1241
994
 
1242
- if (typeof b.title === 'string') secondTitle = b.title as string;
1243
- else secondTitle = b.title.english ?? b.title.romaji ?? '';
995
+ // Use Set for efficient deduplication
996
+ const uniqueResults = Array.from(new Set([...mappedEng, ...mappedRom].map((item) => JSON.stringify(item)))).map(
997
+ (str) => JSON.parse(str)
998
+ );
1244
999
 
1245
- const firstRating = compareTwoStrings(targetTitle, firstTitle.toLowerCase());
1246
- const secondRating = compareTwoStrings(targetTitle, secondTitle.toLowerCase());
1000
+ // Sort by similarity score
1001
+ uniqueResults.sort((a, b) => (b.similarity || 0) - (a.similarity || 0));
1002
+ const mappings: any = {};
1003
+ for (const obj of uniqueResults) {
1004
+ const match = obj.title.replace(/\(TV\)/g, '').match(/\(([^)0-9]+)\)/);
1005
+ const key = match ? match[1].replace(/\s+/g, '-').toLowerCase() : 'sub';
1247
1006
 
1248
- if (firstRating > topRating) {
1249
- topRating = firstRating;
1250
- }
1251
- if (secondRating > topRating) {
1252
- topRating = secondRating;
1007
+ if (!mappings[key]) {
1008
+ mappings[key] = obj.id;
1253
1009
  }
1254
1010
 
1255
- // Sort in descending order
1256
- return secondRating - firstRating;
1257
- });
1258
-
1259
- if (topRating >= 0.7) {
1260
- return await this.provider.fetchAnimeInfo(findAnime.results[0]?.id!);
1011
+ // Early return if we have both sub and dub
1012
+ if (mappings.sub && mappings.dub) break;
1261
1013
  }
1262
-
1263
- return undefined;
1014
+ // console.log('mappings', mappings);
1015
+ // console.time('animeinfo');
1016
+ const animeInfo = await this.provider.fetchAnimeInfo(mappings.sub || mappings.dub);
1017
+ // console.timeEnd('animeinfo');
1018
+ return animeInfo.episodes as IAnimeEpisode[];
1264
1019
  };
1265
-
1266
1020
  /**
1267
1021
  * @returns a random anime
1268
1022
  */
@@ -1350,26 +1104,16 @@ class Anilist extends AnimeParser {
1350
1104
  }
1351
1105
  };
1352
1106
 
1353
- private fetchDefaultEpisodeList = async (
1354
- Media: {
1355
- idMal: number;
1356
- title: { english: string; romaji: string };
1357
- season: string;
1358
- startDate: { year: number };
1359
- externalLinks?: any;
1360
- },
1361
- id: string
1362
- ) => {
1107
+ private fetchDefaultEpisodeList = async (Media: {
1108
+ idMal: number;
1109
+ title: { english: string; romaji: string };
1110
+ season: string;
1111
+ startDate: { year: number };
1112
+ externalLinks?: any;
1113
+ }) => {
1363
1114
  let episodes: IAnimeEpisode[] = [];
1364
1115
 
1365
- episodes = await this.findAnime(
1366
- { english: Media.title?.english!, romaji: Media.title?.romaji! },
1367
- Media.season!,
1368
- Media.startDate.year,
1369
- Media.idMal as number,
1370
- id,
1371
- Media.externalLinks
1372
- );
1116
+ episodes = await this.findAnimeRaw({ english: Media.title?.english!, romaji: Media.title?.romaji! });
1373
1117
  // console.log('fetchDefaultEpisodeList', episodes);
1374
1118
  return episodes;
1375
1119
  };
@@ -1403,10 +1147,12 @@ class Anilist extends AnimeParser {
1403
1147
  this.provider instanceof AnimePahe
1404
1148
  ) {
1405
1149
  try {
1150
+ // console.time('fetchEpisodesListById');
1406
1151
  const [animeMetaData, providerEpisodes] = await Promise.all([
1407
1152
  this.client.get(`https://api.ani.zip/mappings?anilist_id=${id}`).then((res) => res.data),
1408
- this.fetchDefaultEpisodeList(Media, id),
1153
+ this.fetchDefaultEpisodeList(Media),
1409
1154
  ]);
1155
+ // console.timeEnd('fetchEpisodesListById');
1410
1156
  //to get the actual episode ids we make use of fetchDefaultEpisodeList
1411
1157
  const normalizedEpisodes = (
1412
1158
  Object.entries(animeMetaData.episodes || {}) as [string, AniZipEpisode & IAnimeEpisode][]
@@ -1448,7 +1194,7 @@ class Anilist extends AnimeParser {
1448
1194
  // });
1449
1195
  possibleAnimeEpisodes = mergeEpisodes(normalizedEpisodes, providerEpisodes);
1450
1196
  if (!possibleAnimeEpisodes.length) {
1451
- possibleAnimeEpisodes = await this.fetchDefaultEpisodeList(Media, id);
1197
+ possibleAnimeEpisodes = await this.fetchDefaultEpisodeList(Media);
1452
1198
  possibleAnimeEpisodes = possibleAnimeEpisodes?.map((episode: IAnimeEpisode) => {
1453
1199
  if (!episode.image) {
1454
1200
  episode.image = Media.coverImage.extraLarge ?? Media.coverImage.large ?? Media.coverImage.medium;
@@ -1461,7 +1207,7 @@ class Anilist extends AnimeParser {
1461
1207
  });
1462
1208
  }
1463
1209
  } catch (err) {
1464
- possibleAnimeEpisodes = await this.fetchDefaultEpisodeList(Media, id);
1210
+ possibleAnimeEpisodes = await this.fetchDefaultEpisodeList(Media);
1465
1211
 
1466
1212
  possibleAnimeEpisodes = possibleAnimeEpisodes?.map((episode: IAnimeEpisode) => {
1467
1213
  if (!episode.image) {
@@ -1475,7 +1221,7 @@ class Anilist extends AnimeParser {
1475
1221
  });
1476
1222
  return possibleAnimeEpisodes;
1477
1223
  }
1478
- } else possibleAnimeEpisodes = await this.fetchDefaultEpisodeList(Media, id);
1224
+ } else possibleAnimeEpisodes = await this.fetchDefaultEpisodeList(Media);
1479
1225
 
1480
1226
  if (fetchFiller) {
1481
1227
  const { data: fillerData } = await this.client.get(
@@ -12,7 +12,7 @@ import {
12
12
  type IEpisodeServer,
13
13
  MediaFormat,
14
14
  } from '../../models';
15
- import { substringAfter, substringBefore, compareTwoStrings, kitsuSearchQuery, range } from '../../utils';
15
+ import { substringAfter, substringBefore, calculateStringSimilarity, kitsuSearchQuery, range } from '../../utils';
16
16
  import Gogoanime from '../anime/gogoanime';
17
17
  import Zoro from '../anime/zoro';
18
18
  import Anify from '../anime/anify';
@@ -296,8 +296,8 @@ class Myanimelist extends AnimeParser {
296
296
  if (typeof b.title === 'string') secondTitle = b.title as string;
297
297
  else secondTitle = b.title.english ?? b.title.romaji ?? '';
298
298
 
299
- const firstRating = compareTwoStrings(targetTitle, firstTitle.toLowerCase());
300
- const secondRating = compareTwoStrings(targetTitle, secondTitle.toLowerCase());
299
+ const firstRating = calculateStringSimilarity(targetTitle, firstTitle.toLowerCase());
300
+ const secondRating = calculateStringSimilarity(targetTitle, secondTitle.toLowerCase());
301
301
 
302
302
  // Sort in descending order
303
303
  return secondRating - firstRating;
@@ -350,8 +350,8 @@ class Myanimelist extends AnimeParser {
350
350
  sites.sort((a, b) => {
351
351
  const targetTitle = malAsyncReq.data.title.toLowerCase();
352
352
 
353
- const firstRating = compareTwoStrings(targetTitle, a.title.toLowerCase());
354
- const secondRating = compareTwoStrings(targetTitle, b.title.toLowerCase());
353
+ const firstRating = calculateStringSimilarity(targetTitle, a.title.toLowerCase());
354
+ const secondRating = calculateStringSimilarity(targetTitle, b.title.toLowerCase());
355
355
 
356
356
  // Sort in descending order
357
357
  return secondRating - firstRating;