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
package/src/index.tsx CHANGED
@@ -1,3 +1,4 @@
1
+ import 'react-native-url-polyfill/auto';
1
2
  import Consumet from './NativeConsumet';
2
3
 
3
4
  export function getSources(s: string): Promise<string> {
@@ -67,6 +68,7 @@ import {
67
68
  MediaFormat,
68
69
  type ProxyConfig,
69
70
  type AniZipEpisode,
71
+ type IMovieSeason,
70
72
  } from './models';
71
73
 
72
74
  export { ANIME, COMICS, MANGA, LIGHT_NOVELS, MOVIES, META, NEWS };
@@ -133,4 +135,5 @@ export type {
133
135
  ITitle,
134
136
  ProxyConfig,
135
137
  AniZipEpisode,
138
+ IMovieSeason,
136
139
  };
@@ -48,6 +48,7 @@ import {
48
48
  type IStaff,
49
49
  WatchListType,
50
50
  type AniZipEpisode,
51
+ type IMovieSeason,
51
52
  } from './types';
52
53
  import { LibgenBookObject, GetComicsComicsObject } from './type-objects';
53
54
 
@@ -105,4 +106,5 @@ export type {
105
106
  ProxyConfig,
106
107
  IStaff,
107
108
  AniZipEpisode,
109
+ IMovieSeason,
108
110
  };
@@ -1,51 +1,95 @@
1
1
  import axios, { type AxiosAdapter, type AxiosInstance } from 'axios';
2
-
3
2
  import type { ProxyConfig } from './types';
4
3
 
5
4
  export class Proxy {
6
- /**
7
- *
8
- * @param proxyConfig The proxy config (optional)
9
- * @param adapter The axios adapter (optional)
10
- */
5
+ protected client: AxiosInstance;
6
+ private validUrl = /^https?:\/\/.+/;
7
+ private proxyUrl: string | null = null;
8
+ private proxyKey: string | null = null;
9
+ private rotationTimer: NodeJS.Timeout | null = null;
10
+
11
11
  constructor(
12
12
  protected proxyConfig?: ProxyConfig,
13
13
  protected adapter?: AxiosAdapter
14
14
  ) {
15
- this.client = axios.create();
15
+ // Create client with optimized defaults for React Native
16
+ this.client = axios.create({
17
+ // Increase timeout for mobile networks
18
+ timeout: 15000,
19
+ // Add headers only once here
20
+ headers: {
21
+ 'Accept': 'application/json, text/plain, */*',
22
+ 'Content-Type': 'application/json',
23
+ },
24
+ });
25
+
26
+ // Apply adapter if provided
27
+ if (adapter) this.client.defaults.adapter = adapter;
28
+
29
+ // Set up interceptor only once
30
+ this.setupInterceptor();
16
31
 
32
+ // Apply proxy if provided
17
33
  if (proxyConfig) this.setProxy(proxyConfig);
18
- if (adapter) this.setAxiosAdapter(adapter);
19
34
  }
20
- private validUrl = /^https?:\/\/.+/;
35
+
36
+ private setupInterceptor() {
37
+ // Set the interceptor once during initialization
38
+ this.client.interceptors.request.use((config) => {
39
+ // Only modify URL if we have a proxy
40
+ if (this.proxyUrl) {
41
+ config.url = `${this.proxyUrl}${config?.url || ''}`;
42
+
43
+ // Only set header if we have a key
44
+ if (this.proxyKey) {
45
+ config.headers.set('x-api-key', this.proxyKey);
46
+ }
47
+ }
48
+
49
+ // Special case for anify
50
+ if (config?.url?.includes('anify')) {
51
+ config.headers.set('User-Agent', 'consumet');
52
+ }
53
+
54
+ return config;
55
+ });
56
+ }
57
+
21
58
  /**
22
59
  * Set or Change the proxy config
23
60
  */
24
61
  setProxy(proxyConfig: ProxyConfig) {
25
- if (!proxyConfig?.url) return;
62
+ // Clear any existing rotation timer
63
+ if (this.rotationTimer) {
64
+ clearInterval(this.rotationTimer);
65
+ this.rotationTimer = null;
66
+ }
26
67
 
27
- if (typeof proxyConfig?.url === 'string')
28
- if (!this.validUrl.test(proxyConfig.url)) throw new Error('Proxy URL is invalid!');
68
+ // Early return if no URL
69
+ if (!proxyConfig?.url) return;
29
70
 
71
+ // Handle array of URLs
30
72
  if (Array.isArray(proxyConfig?.url)) {
31
- for (const [i, url] of this.toMap<string>(proxyConfig.url))
32
- if (!this.validUrl.test(url)) throw new Error(`Proxy URL at index ${i} is invalid!`);
73
+ // Validate all URLs first
74
+ for (const [i, url] of this.toMap<string>(proxyConfig.url)) {
75
+ if (!this.validUrl.test(url)) {
76
+ throw new Error(`Proxy URL at index ${i} is invalid!`);
77
+ }
78
+ }
33
79
 
80
+ // Start rotation with validated URLs
34
81
  this.rotateProxy({ ...proxyConfig, urls: proxyConfig.url });
35
-
36
82
  return;
37
83
  }
38
84
 
39
- this.client.interceptors.request.use((config) => {
40
- if (proxyConfig?.url) {
41
- config.headers.set('x-api-key', proxyConfig?.key ?? '');
42
- config.url = `${proxyConfig.url}${config?.url ? config?.url : ''}`;
43
- }
44
-
45
- if (config?.url?.includes('anify')) config.headers.set('User-Agent', 'consumet');
85
+ // Handle single URL
86
+ if (!this.validUrl.test(proxyConfig.url)) {
87
+ throw new Error('Proxy URL is invalid!');
88
+ }
46
89
 
47
- return config;
48
- });
90
+ // Store proxy settings (used by interceptor)
91
+ this.proxyUrl = proxyConfig.url;
92
+ this.proxyKey = proxyConfig.key ?? null;
49
93
  }
50
94
 
51
95
  /**
@@ -54,18 +98,24 @@ export class Proxy {
54
98
  setAxiosAdapter(adapter: AxiosAdapter) {
55
99
  this.client.defaults.adapter = adapter;
56
100
  }
101
+
57
102
  private rotateProxy = (proxy: Omit<ProxyConfig, 'url'> & { urls: string[] }) => {
58
- setInterval(() => {
59
- const url = proxy.urls.shift();
60
- if (url) proxy.urls.push(url);
103
+ // Start with first URL
104
+ this.proxyUrl = proxy.urls[0]!;
105
+ this.proxyKey = proxy.key ?? null;
106
+
107
+ // Set up rotation
108
+ let index = 0;
109
+ const urlCount = proxy.urls.length;
61
110
 
62
- this.setProxy({ url: proxy.urls[0]!, key: proxy.key });
111
+ this.rotationTimer = setInterval(() => {
112
+ // Move to next URL in array
113
+ index = (index + 1) % urlCount;
114
+ this.proxyUrl = proxy.urls[index]!;
63
115
  }, proxy?.rotateInterval ?? 5000);
64
116
  };
65
117
 
66
118
  private toMap = <T>(arr: T[]): [number, T][] => arr.map((v, i) => [i, v]);
67
-
68
- protected client: AxiosInstance;
69
119
  }
70
120
 
71
121
  export default Proxy;
@@ -392,7 +392,12 @@ export interface IMovieEpisode {
392
392
  number?: number;
393
393
  season?: number;
394
394
  description?: string;
395
- image?: string;
395
+ image?:
396
+ | string
397
+ | {
398
+ mobile?: string;
399
+ hd?: string;
400
+ };
396
401
  releaseDate?: string;
397
402
  [x: string]: unknown; // other fields
398
403
  }
@@ -15,6 +15,7 @@ import {
15
15
  } from '../../models';
16
16
 
17
17
  import { MegaUp } from '../../utils';
18
+ import axios from 'axios';
18
19
 
19
20
  const { GenerateToken, DecodeIframeData } = new MegaUp();
20
21
 
@@ -299,7 +300,7 @@ class AnimeKai extends AnimeParser {
299
300
  title: '',
300
301
  };
301
302
  try {
302
- const { data } = await this.client.get(`${this.baseUrl}/watch/${id}`, {
303
+ const { data } = await axios.get(`${this.baseUrl}/watch/${id}`, {
303
304
  headers: this.Headers(),
304
305
  });
305
306
  const $ = load(data);
@@ -388,7 +389,7 @@ class AnimeKai extends AnimeParser {
388
389
  info.season = $('.entity-scroll > .detail').find("div:contains('Premiered') > span").text().trim();
389
390
 
390
391
  const ani_id = $('.rate-box#anime-rating').attr('data-id');
391
- const episodesAjax = await this.client.get(
392
+ const episodesAjax = await axios.get(
392
393
  `${this.baseUrl}/ajax/episodes/list?ani_id=${ani_id}&_=${GenerateToken(ani_id!)}`,
393
394
  {
394
395
  headers: {
@@ -400,26 +401,28 @@ class AnimeKai extends AnimeParser {
400
401
  );
401
402
  const $$ = load(episodesAjax.data.result);
402
403
 
404
+ // Pre-calculate values used for all episodes
405
+ const episodeElements = $$('div.eplist > ul > li > a');
406
+ const subCount = parseInt($('.entity-scroll > .info > span.sub').text().trim()) || 0;
407
+ const dubCount = parseInt($('.entity-scroll > .info > span.dub').text().trim()) || 0;
408
+
403
409
  info.totalEpisodes = $$('div.eplist > ul > li').length;
404
410
  info.episodes = [];
405
411
 
406
- $$('div.eplist > ul > li > a').each((i, el) => {
412
+ episodeElements.each((i, el) => {
413
+ const $el = $$(el);
414
+ const href = `${$el.attr('href')}ep=${$el.attr('num')}` || '';
415
+ const number = parseInt($el.attr('data-number') || '0');
407
416
  const episodeId = `${info.id}$ep=${$$(el).attr('num')}$token=${$$(el).attr('token')}`; //appending token to episode id, as it is required to fetch servers keeping the structure same as other providers
408
- const number = parseInt($$(el).attr('num')!);
409
- const title = $$(el).children('span').text().trim();
410
- const url = `${this.baseUrl}/watch/${info.id}${$$(el).attr('href')}ep=${$$(el).attr('num')}`;
411
- const isFiller = $$(el).hasClass('filler');
412
- const isSubbed = number <= (parseInt($('.entity-scroll > .info > span.sub').text().trim()) || 0);
413
- const isDubbed = number <= (parseInt($('.entity-scroll > .info > span.dub').text().trim()) || 0);
414
417
 
415
418
  info.episodes?.push({
416
419
  id: episodeId,
417
420
  number: number,
418
- title: title,
419
- isFiller: isFiller,
420
- isSubbed: isSubbed,
421
- isDubbed: isDubbed,
422
- url: url,
421
+ title: $el.children('span').text().trim(),
422
+ isFiller: $el.hasClass('filler'),
423
+ isSubbed: number <= subCount,
424
+ isDubbed: number <= dubCount,
425
+ url: this.baseUrl + href,
423
426
  });
424
427
  });
425
428
 
@@ -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
  };