react-native-consumet 1.1.0 → 1.2.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 (111) hide show
  1. package/README.md +19 -0
  2. package/lib/commonjs/extension-registry.json +30 -1
  3. package/lib/commonjs/extractors/index.js +2 -2
  4. package/lib/commonjs/extractors/index.js.map +1 -1
  5. package/lib/commonjs/extractors/megacloud.js +11 -5
  6. package/lib/commonjs/extractors/megacloud.js.map +1 -1
  7. package/lib/commonjs/extractors/megaup.js +87 -84
  8. package/lib/commonjs/extractors/megaup.js.map +1 -1
  9. package/lib/commonjs/index.js +1 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/providers/anime/animekai/animekai.js +118 -0
  12. package/lib/commonjs/providers/anime/animekai/animekai.js.map +1 -0
  13. package/lib/commonjs/providers/anime/animekai/create-animekai.js +507 -0
  14. package/lib/commonjs/providers/anime/animekai/create-animekai.js.map +1 -0
  15. package/lib/commonjs/providers/anime/index.js +4 -2
  16. package/lib/commonjs/providers/anime/index.js.map +1 -1
  17. package/lib/commonjs/providers/meta/anilist.js +1 -1
  18. package/lib/commonjs/providers/movies/multistream/utils.js +252 -26
  19. package/lib/commonjs/providers/movies/multistream/utils.js.map +1 -1
  20. package/lib/commonjs/utils/extension-utils.js +1 -1
  21. package/lib/commonjs/utils/extension-utils.js.map +1 -1
  22. package/lib/commonjs/utils/provider-maps.js +3 -0
  23. package/lib/commonjs/utils/provider-maps.js.map +1 -1
  24. package/lib/module/extension-registry.json +30 -1
  25. package/lib/module/extractors/index.js +1 -1
  26. package/lib/module/extractors/index.js.map +1 -1
  27. package/lib/module/extractors/megacloud.js +11 -5
  28. package/lib/module/extractors/megacloud.js.map +1 -1
  29. package/lib/module/extractors/megaup.js +85 -82
  30. package/lib/module/extractors/megaup.js.map +1 -1
  31. package/lib/module/index.js +1 -0
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/module/providers/anime/animekai/animekai.js +112 -0
  34. package/lib/module/providers/anime/animekai/animekai.js.map +1 -0
  35. package/lib/module/providers/anime/animekai/create-animekai.js +503 -0
  36. package/lib/module/providers/anime/animekai/create-animekai.js.map +1 -0
  37. package/lib/module/providers/anime/index.js +4 -2
  38. package/lib/module/providers/anime/index.js.map +1 -1
  39. package/lib/module/providers/meta/anilist.js +1 -1
  40. package/lib/module/providers/meta/anilist.js.map +1 -1
  41. package/lib/module/providers/movies/multistream/utils.js +249 -26
  42. package/lib/module/providers/movies/multistream/utils.js.map +1 -1
  43. package/lib/module/utils/extension-utils.js +1 -1
  44. package/lib/module/utils/extension-utils.js.map +1 -1
  45. package/lib/module/utils/provider-maps.js +3 -0
  46. package/lib/module/utils/provider-maps.js.map +1 -1
  47. package/lib/typescript/commonjs/src/extractors/index.d.ts +1 -1
  48. package/lib/typescript/commonjs/src/extractors/index.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/src/extractors/megacloud.d.ts.map +1 -1
  50. package/lib/typescript/commonjs/src/extractors/megaup.d.ts +5 -15
  51. package/lib/typescript/commonjs/src/extractors/megaup.d.ts.map +1 -1
  52. package/lib/typescript/commonjs/src/index.d.ts +1 -0
  53. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  54. package/lib/typescript/commonjs/src/models/provider-context.d.ts +2 -2
  55. package/lib/typescript/commonjs/src/models/provider-context.d.ts.map +1 -1
  56. package/lib/typescript/commonjs/src/providers/anime/animekai/animekai.d.ts +83 -0
  57. package/lib/typescript/commonjs/src/providers/anime/animekai/animekai.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/providers/anime/animekai/create-animekai.d.ts +28 -0
  59. package/lib/typescript/commonjs/src/providers/anime/animekai/create-animekai.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/providers/anime/index.d.ts +3 -1
  61. package/lib/typescript/commonjs/src/providers/anime/index.d.ts.map +1 -1
  62. package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts +9 -0
  63. package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts.map +1 -1
  64. package/lib/typescript/commonjs/src/utils/extension-utils.d.ts +2 -2
  65. package/lib/typescript/commonjs/src/utils/extension-utils.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/src/utils/provider-maps.d.ts +1 -0
  67. package/lib/typescript/commonjs/src/utils/provider-maps.d.ts.map +1 -1
  68. package/lib/typescript/module/src/extractors/index.d.ts +1 -1
  69. package/lib/typescript/module/src/extractors/index.d.ts.map +1 -1
  70. package/lib/typescript/module/src/extractors/megacloud.d.ts.map +1 -1
  71. package/lib/typescript/module/src/extractors/megaup.d.ts +5 -15
  72. package/lib/typescript/module/src/extractors/megaup.d.ts.map +1 -1
  73. package/lib/typescript/module/src/index.d.ts +1 -0
  74. package/lib/typescript/module/src/index.d.ts.map +1 -1
  75. package/lib/typescript/module/src/models/provider-context.d.ts +2 -2
  76. package/lib/typescript/module/src/models/provider-context.d.ts.map +1 -1
  77. package/lib/typescript/module/src/providers/anime/animekai/animekai.d.ts +83 -0
  78. package/lib/typescript/module/src/providers/anime/animekai/animekai.d.ts.map +1 -0
  79. package/lib/typescript/module/src/providers/anime/animekai/create-animekai.d.ts +28 -0
  80. package/lib/typescript/module/src/providers/anime/animekai/create-animekai.d.ts.map +1 -0
  81. package/lib/typescript/module/src/providers/anime/index.d.ts +3 -1
  82. package/lib/typescript/module/src/providers/anime/index.d.ts.map +1 -1
  83. package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts +9 -0
  84. package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts.map +1 -1
  85. package/lib/typescript/module/src/utils/extension-utils.d.ts +2 -2
  86. package/lib/typescript/module/src/utils/extension-utils.d.ts.map +1 -1
  87. package/lib/typescript/module/src/utils/provider-maps.d.ts +1 -0
  88. package/lib/typescript/module/src/utils/provider-maps.d.ts.map +1 -1
  89. package/package.json +4 -5
  90. package/src/extension-registry.json +30 -1
  91. package/src/extractors/index.ts +1 -1
  92. package/src/extractors/megacloud.ts +11 -5
  93. package/src/extractors/megaup.ts +92 -88
  94. package/src/index.tsx +1 -0
  95. package/src/models/provider-context.ts +2 -2
  96. package/src/providers/anime/animekai/animekai.ts +121 -0
  97. package/src/providers/anime/animekai/create-animekai.ts +579 -0
  98. package/src/providers/anime/index.ts +3 -1
  99. package/src/providers/meta/anilist.ts +1 -1
  100. package/src/providers/movies/multistream/utils.ts +213 -16
  101. package/src/utils/extension-utils.ts +1 -1
  102. package/src/utils/provider-maps.ts +3 -0
  103. package/lib/commonjs/providers/anime/animekai.js +0 -587
  104. package/lib/commonjs/providers/anime/animekai.js.map +0 -1
  105. package/lib/module/providers/anime/animekai.js +0 -583
  106. package/lib/module/providers/anime/animekai.js.map +0 -1
  107. package/lib/typescript/commonjs/src/providers/anime/animekai.d.ts +0 -89
  108. package/lib/typescript/commonjs/src/providers/anime/animekai.d.ts.map +0 -1
  109. package/lib/typescript/module/src/providers/anime/animekai.d.ts +0 -89
  110. package/lib/typescript/module/src/providers/anime/animekai.d.ts.map +0 -1
  111. package/src/providers/anime/animekai.ts +0 -627
@@ -0,0 +1,579 @@
1
+ import type { CheerioAPI } from 'cheerio';
2
+ import {
3
+ type ISearch,
4
+ type IAnimeInfo,
5
+ type IAnimeResult,
6
+ type ISource,
7
+ type IEpisodeServer,
8
+ type StreamingServers,
9
+ type MediaFormat,
10
+ type SubOrDub,
11
+ type ProviderContext,
12
+ type ProviderConfig,
13
+ type Intro,
14
+ } from '../../../models';
15
+
16
+ function createAnimeKai(ctx: ProviderContext, customBaseURL?: string) {
17
+ const { axios, load, enums, createCustomBaseUrl, USER_AGENT, PolyURL, extractors } = ctx;
18
+ const { StreamingServers: StreamingServersEnum, MediaStatus: MediaStatusEnum, SubOrDub: SubOrDubEnum } = enums;
19
+ const { MegaUp } = extractors;
20
+
21
+ const baseUrl = createCustomBaseUrl('https://anikai.to', customBaseURL);
22
+ const apiBase = 'https://enc-dec.app/api';
23
+
24
+ const config: ProviderConfig = {
25
+ name: 'AnimeKai',
26
+ languages: 'en',
27
+ classPath: 'ANIME.AnimeKai',
28
+ logo: 'https://anikai.to/assets/uploads/37585a3ffa8ec292ee9e2255f3f63b48ceca17e5241280b3dc21.png',
29
+ baseUrl,
30
+ isNSFW: false,
31
+ isWorking: true,
32
+ isDubAvailableSeparately: true,
33
+ };
34
+
35
+ const buildHeaders = (): Record<string, string> => ({
36
+ 'User-Agent':
37
+ USER_AGENT ||
38
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36',
39
+ 'Connection': 'keep-alive',
40
+ 'Accept': 'text/html, */*; q=0.01',
41
+ 'Accept-Language': 'en-US,en;q=0.5',
42
+ 'Sec-GPC': '1',
43
+ 'Sec-Fetch-Dest': 'empty',
44
+ 'Sec-Fetch-Mode': 'cors',
45
+ 'Sec-Fetch-Site': 'same-origin',
46
+ 'Priority': 'u=0',
47
+ 'Pragma': 'no-cache',
48
+ 'Cache-Control': 'no-cache',
49
+ 'Referer': `${config.baseUrl}/`,
50
+ 'Cookie': '__p_mov=1; usertype=guest; session=vLrU4aKItp0QltI2asH83yugyWDsSSQtyl9sxWKO',
51
+ });
52
+
53
+ const normalizePage = (page: number = 1): number => (page <= 0 ? 1 : page);
54
+
55
+ const scrapeCard = async ($: CheerioAPI): Promise<IAnimeResult[]> => {
56
+ const results: IAnimeResult[] = [];
57
+
58
+ $('.aitem').each((_, element) => {
59
+ const card = $(element);
60
+ const anchor = card.find('div.inner > a');
61
+ const id = anchor.attr('href')?.replace('/watch/', '');
62
+ if (!id) return;
63
+
64
+ const infoElements = card.find('.info').children();
65
+ const type = infoElements.last()?.text().trim();
66
+
67
+ results.push({
68
+ id,
69
+ title: anchor.text().trim(),
70
+ url: `${config.baseUrl}${anchor.attr('href')}`,
71
+ image: card.find('img')?.attr('data-src') ?? card.find('img')?.attr('src') ?? undefined,
72
+ japaneseTitle: card.find('a.title')?.attr('data-jp')?.trim(),
73
+ type: (type as MediaFormat) ?? undefined,
74
+ sub: parseInt(card.find('.info span.sub')?.text() || '0', 10),
75
+ dub: parseInt(card.find('.info span.dub')?.text() || '0', 10),
76
+ episodes: parseInt(infoElements.eq(-2).text().trim() || card.find('.info span.sub')?.text() || '0', 10) || 0,
77
+ });
78
+ });
79
+
80
+ return results;
81
+ };
82
+
83
+ const scrapeCardPage = async (url: string): Promise<ISearch<IAnimeResult>> => {
84
+ const res: ISearch<IAnimeResult> = {
85
+ currentPage: 0,
86
+ hasNextPage: false,
87
+ totalPages: 0,
88
+ results: [],
89
+ };
90
+
91
+ const { data } = await axios.get(url, { headers: buildHeaders() });
92
+ const $ = load(data);
93
+
94
+ const pagination = $('ul.pagination');
95
+ res.currentPage = parseInt(pagination.find('.page-item.active span.page-link').text().trim(), 10) || 0;
96
+ const nextHref = pagination.find('.page-item.active').next().find('a.page-link').attr('href');
97
+ res.hasNextPage = Boolean(nextHref && nextHref.includes('page='));
98
+
99
+ const totalHref = pagination.find('.page-item:last-child a.page-link').attr('href');
100
+ res.totalPages =
101
+ totalHref && totalHref.includes('page=')
102
+ ? parseInt(totalHref.split('page=')[1] ?? '0', 10) || 0
103
+ : res.currentPage;
104
+
105
+ res.results = await scrapeCard($);
106
+ if (res.results.length === 0) {
107
+ res.currentPage = 0;
108
+ res.hasNextPage = false;
109
+ res.totalPages = 0;
110
+ }
111
+
112
+ return res;
113
+ };
114
+
115
+ const search = async (query: string, page: number = 1): Promise<ISearch<IAnimeResult>> => {
116
+ const normalizedPage = normalizePage(page);
117
+ const sanitizedQuery = query.replace(/[^\w]+/g, '+');
118
+ return scrapeCardPage(`${config.baseUrl}/browser?keyword=${sanitizedQuery}&page=${normalizedPage}`);
119
+ };
120
+
121
+ const fetchLatestCompleted = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
122
+ return scrapeCardPage(`${config.baseUrl}/completed?page=${normalizePage(page)}`);
123
+ };
124
+
125
+ const fetchRecentlyAdded = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
126
+ return scrapeCardPage(`${config.baseUrl}/recent?page=${normalizePage(page)}`);
127
+ };
128
+
129
+ const fetchRecentlyUpdated = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
130
+ return scrapeCardPage(`${config.baseUrl}/updates?page=${normalizePage(page)}`);
131
+ };
132
+
133
+ const fetchNewReleases = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
134
+ return scrapeCardPage(`${config.baseUrl}/new-releases?page=${normalizePage(page)}`);
135
+ };
136
+
137
+ const fetchMovie = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
138
+ return scrapeCardPage(`${config.baseUrl}/movie?page=${normalizePage(page)}`);
139
+ };
140
+
141
+ const fetchTV = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
142
+ return scrapeCardPage(`${config.baseUrl}/tv?page=${normalizePage(page)}`);
143
+ };
144
+
145
+ const fetchOVA = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
146
+ return scrapeCardPage(`${config.baseUrl}/ova?page=${normalizePage(page)}`);
147
+ };
148
+
149
+ const fetchONA = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
150
+ return scrapeCardPage(`${config.baseUrl}/ona?page=${normalizePage(page)}`);
151
+ };
152
+
153
+ const fetchSpecial = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
154
+ return scrapeCardPage(`${config.baseUrl}/special?page=${normalizePage(page)}`);
155
+ };
156
+
157
+ const fetchGenres = async (): Promise<string[]> => {
158
+ const genres: string[] = [];
159
+ const { data } = await axios.get(`${config.baseUrl}/home`, { headers: buildHeaders() });
160
+ const $ = load(data);
161
+
162
+ $('#menu')
163
+ .find('ul.c4 li a')
164
+ .each((_, element) => {
165
+ const genreText = $(element).text().toLowerCase();
166
+ if (genreText) genres.push(genreText);
167
+ });
168
+
169
+ return genres;
170
+ };
171
+
172
+ const genreSearch = async (genre: string, page: number = 1): Promise<ISearch<IAnimeResult>> => {
173
+ if (!genre) {
174
+ throw new Error('genre is empty');
175
+ }
176
+
177
+ return scrapeCardPage(`${config.baseUrl}/genres/${genre}?page=${normalizePage(page)}`);
178
+ };
179
+
180
+ const fetchSchedule = async (
181
+ date: string = new Date().toISOString().split('T')[0]!
182
+ ): Promise<ISearch<IAnimeResult>> => {
183
+ const res: ISearch<IAnimeResult> = { results: [] };
184
+ const scheduleUnix = Math.floor(new Date(`${date}T00:00:00Z`).getTime() / 1000);
185
+ const { data } = await axios.get(`${config.baseUrl}/ajax/schedule/items?tz=5.5&time=${scheduleUnix}`, {
186
+ headers: buildHeaders(),
187
+ });
188
+ const $ = load(data.result);
189
+
190
+ $('ul.collapsed li').each((_, element) => {
191
+ const card = $(element);
192
+ const titleElement = card.find('span.title');
193
+ const episodeText = card.find('span').last().text().trim();
194
+
195
+ const id = card.find('a').attr('href')?.split('/')[2] ?? '';
196
+ if (!id) return;
197
+
198
+ res.results.push({
199
+ id,
200
+ title: titleElement.text().trim(),
201
+ japaneseTitle: titleElement.attr('data-jp') || undefined,
202
+ airingTime: card.find('span.time').text().trim(),
203
+ airingEpisode: episodeText.replace('EP ', ''),
204
+ });
205
+ });
206
+
207
+ return res;
208
+ };
209
+
210
+ const fetchSpotlight = async (): Promise<ISearch<IAnimeResult>> => {
211
+ const res: ISearch<IAnimeResult> = { results: [] };
212
+ const { data } = await axios.get(`${config.baseUrl}/home`, { headers: buildHeaders() });
213
+ const $ = load(data);
214
+
215
+ $('div.swiper-wrapper > div.swiper-slide').each((_, element) => {
216
+ const card = $(element);
217
+ const titleElement = card.find('div.detail > p.title');
218
+ const id = card.find('div.swiper-ctrl > a.btn').attr('href')?.replace('/watch/', '') || '';
219
+ if (!id) return;
220
+
221
+ const infoElements = card.find('div.detail > div.info').children();
222
+
223
+ res.results.push({
224
+ id,
225
+ title: titleElement.text(),
226
+ japaneseTitle: titleElement.attr('data-jp') || undefined,
227
+ banner: card.attr('style')?.match(/background-image:\s*url\(["']?(.+?)["']?\)/)?.[1] || null,
228
+ url: `${config.baseUrl}/watch/${id}`,
229
+ type: infoElements.eq(-2).text().trim() as MediaFormat,
230
+ genres: infoElements
231
+ .last()
232
+ .text()
233
+ .trim()
234
+ .split(',')
235
+ .map((genre) => genre.trim()),
236
+ releaseDate: card.find('div.detail > div.mics > div:contains("Release") span').text().trim(),
237
+ quality: card.find('div.detail > div.mics > div:contains("Quality") span').text().trim(),
238
+ sub: parseInt(card.find('div.detail > div.info > span.sub').text().trim() || '0', 10),
239
+ dub: parseInt(card.find('div.detail > div.info > span.dub').text().trim() || '0', 10),
240
+ description: card.find('div.detail > p.desc').text().trim(),
241
+ });
242
+ });
243
+
244
+ return res;
245
+ };
246
+
247
+ const fetchSearchSuggestions = async (query: string): Promise<ISearch<IAnimeResult>> => {
248
+ const { data } = await axios.get(`${config.baseUrl}/ajax/anime/search?keyword=${query.replace(/[^\w]+/g, '+')}`, {
249
+ headers: buildHeaders(),
250
+ });
251
+ const $ = load(data.result.html);
252
+ const res: ISearch<IAnimeResult> = { results: [] };
253
+
254
+ $('a.aitem').each((_, element) => {
255
+ const card = $(element);
256
+ const id = card.attr('href')?.split('/')[2];
257
+ if (!id) return;
258
+
259
+ const infoElements = card.find('.info').children();
260
+ const titleElement = card.find('.title');
261
+
262
+ res.results.push({
263
+ id,
264
+ title: titleElement.text().trim(),
265
+ url: `${config.baseUrl}/watch/${id}`,
266
+ image: card.find('.poster img').attr('src') || undefined,
267
+ japaneseTitle: titleElement.attr('data-jp') || undefined,
268
+ type: infoElements.eq(-3).text().trim() as MediaFormat,
269
+ year: infoElements.eq(-2).text().trim(),
270
+ sub: parseInt(card.find('.info span.sub')?.text() || '0', 10),
271
+ dub: parseInt(card.find('.info span.dub')?.text() || '0', 10),
272
+ episodes: parseInt(infoElements.eq(-4).text().trim() || card.find('.info span.sub')?.text() || '0', 10) || 0,
273
+ });
274
+ });
275
+
276
+ return res;
277
+ };
278
+
279
+ const fetchAnimeInfo = async (id: string): Promise<IAnimeInfo> => {
280
+ const info: IAnimeInfo = { id, title: '' };
281
+
282
+ const { data } = await axios.get(`${config.baseUrl}/watch/${id}`, { headers: buildHeaders() });
283
+ const $ = load(data);
284
+
285
+ info.title = $('.entity-scroll > .title').text().trim();
286
+ info.japaneseTitle = $('.entity-scroll > .title').attr('data-jp')?.trim();
287
+ info.image = $('div.poster > div > img').attr('src');
288
+ info.description = $('.entity-scroll > .desc').text().trim();
289
+ info.type = $('.entity-scroll > .info').children().last().text().trim().toUpperCase() as MediaFormat;
290
+ info.url = `${config.baseUrl}/watch/${id}`;
291
+
292
+ info.recommendations = [];
293
+ $('section.sidebar-section:not(#related-anime) .aitem-col .aitem').each((_, element) => {
294
+ const card = $(element);
295
+ const recommendationId = card.attr('href')?.replace('/watch/', '');
296
+ if (!recommendationId) return;
297
+
298
+ info.recommendations?.push({
299
+ id: recommendationId,
300
+ title: card.find('.title').text().trim(),
301
+ url: `${config.baseUrl}${card.attr('href')}`,
302
+ image: card.attr('style')?.match(/background-image:\s*url\('(.+?)'\)/)?.[1] ?? undefined,
303
+ japaneseTitle: card.find('.title').attr('data-jp')?.trim(),
304
+ type: card.find('.info').children().last().text().trim() as MediaFormat,
305
+ sub: parseInt(card.find('.info span.sub')?.text() || '0', 10),
306
+ dub: parseInt(card.find('.info span.dub')?.text() || '0', 10),
307
+ episodes:
308
+ parseInt(
309
+ card.find('.info').children().eq(-2).text().trim() || card.find('.info span.sub')?.text() || '0',
310
+ 10
311
+ ) || 0,
312
+ });
313
+ });
314
+
315
+ info.relations = [];
316
+ $('section#related-anime .tab-body .aitem-col').each((_, element) => {
317
+ const card = $(element);
318
+ const relationAnchor = card.find('a.aitem');
319
+ const relationId = relationAnchor.attr('href')?.replace('/watch/', '');
320
+ if (!relationId) return;
321
+
322
+ info.relations?.push({
323
+ id: relationId,
324
+ title: relationAnchor.find('.title').text().trim(),
325
+ url: `${config.baseUrl}${relationAnchor.attr('href')}`,
326
+ image: relationAnchor.attr('style')?.match(/background-image:\s*url\('(.+?)'\)/)?.[1] ?? undefined,
327
+ japaneseTitle: relationAnchor.find('.title').attr('data-jp')?.trim(),
328
+ type: card.find('.info').children().eq(-2).text().trim() as MediaFormat,
329
+ sub: parseInt(card.find('.info span.sub')?.text() || '0', 10),
330
+ dub: parseInt(card.find('.info span.dub')?.text() || '0', 10),
331
+ relationType: card.find('.info').children().last().text().trim(),
332
+ episodes:
333
+ parseInt(
334
+ card.find('.info').children().eq(-3).text().trim() || card.find('.info span.sub')?.text() || '0',
335
+ 10
336
+ ) || 0,
337
+ });
338
+ });
339
+
340
+ const hasSub = $('.entity-scroll > .info > span.sub').length > 0;
341
+ const hasDub = $('.entity-scroll > .info > span.dub').length > 0;
342
+
343
+ if (hasSub && hasDub) {
344
+ info.subOrDub = SubOrDubEnum.BOTH;
345
+ } else if (hasSub) {
346
+ info.subOrDub = SubOrDubEnum.SUB;
347
+ } else if (hasDub) {
348
+ info.subOrDub = SubOrDubEnum.DUB;
349
+ }
350
+
351
+ info.hasSub = hasSub;
352
+ info.hasDub = hasDub;
353
+
354
+ info.genres = [];
355
+ $('.entity-scroll > .detail')
356
+ .find("div:contains('Genres')")
357
+ .each(function () {
358
+ const genre = $(this).text().trim();
359
+ if (genre) info.genres?.push(genre);
360
+ });
361
+
362
+ const statusText = $('.entity-scroll > .detail').find("div:contains('Status') > span").text().trim();
363
+
364
+ switch (statusText) {
365
+ case 'Completed':
366
+ info.status = MediaStatusEnum.COMPLETED;
367
+ break;
368
+ case 'Releasing':
369
+ info.status = MediaStatusEnum.ONGOING;
370
+ break;
371
+ case 'Not yet aired':
372
+ info.status = MediaStatusEnum.NOT_YET_AIRED;
373
+ break;
374
+ default:
375
+ info.status = MediaStatusEnum.UNKNOWN;
376
+ break;
377
+ }
378
+
379
+ info.season = $('.entity-scroll > .detail').find("div:contains('Premiered') > span").text().trim();
380
+
381
+ const totalEpisodes = $('div.eplist > ul > li').length;
382
+ info.totalEpisodes = totalEpisodes;
383
+
384
+ const aniId = $('.rate-box#anime-rating').attr('data-id');
385
+ if (!aniId) {
386
+ throw new Error('Failed to locate anime id');
387
+ }
388
+
389
+ const episodeToken = await GenerateToken(aniId);
390
+ const episodesResponse = await axios.get(`${config.baseUrl}/ajax/episodes/list?ani_id=${aniId}&_=${episodeToken}`, {
391
+ headers: {
392
+ 'X-Requested-With': 'XMLHttpRequest',
393
+ 'Referer': `${config.baseUrl}/watch/${id}`,
394
+ ...buildHeaders(),
395
+ },
396
+ });
397
+ const $$ = load(episodesResponse.data.result);
398
+
399
+ const subCount = parseInt($('.entity-scroll > .info > span.sub').text().trim() || '0', 10);
400
+ const dubCount = parseInt($('.entity-scroll > .info > span.dub').text().trim() || '0', 10);
401
+
402
+ info.episodes = [];
403
+ $$('div.eplist > ul > li > a').each((_, element) => {
404
+ const el = $$(element);
405
+ const href = `${el.attr('href')}ep=${el.attr('num')}` || '';
406
+ const number = parseInt(el.attr('data-number') || '0', 10);
407
+ const token = el.attr('token');
408
+ if (!token) return;
409
+
410
+ const epId = `${info.id}$ep=${el.attr('num')}$token=${token}`;
411
+
412
+ info.episodes?.push({
413
+ id: epId,
414
+ number,
415
+ title: el.children('span').text().trim(),
416
+ isFiller: el.hasClass('filler'),
417
+ isSubbed: number <= subCount,
418
+ isDubbed: number <= dubCount,
419
+ url: `${config.baseUrl}${href}`,
420
+ });
421
+ });
422
+
423
+ return info;
424
+ };
425
+
426
+ const fetchEpisodeServers = async (
427
+ episodeId: string,
428
+ subOrDub: SubOrDub = SubOrDubEnum.SUB
429
+ ): Promise<IEpisodeServer[]> => {
430
+ let requestUrl = episodeId;
431
+
432
+ if (!episodeId.startsWith(`${config.baseUrl}/ajax`)) {
433
+ const token = episodeId.split('$token=')[1];
434
+ if (!token) {
435
+ throw new Error('Invalid episodeId format: missing token');
436
+ }
437
+ const listToken = await GenerateToken(token);
438
+ requestUrl = `${config.baseUrl}/ajax/links/list?token=${token}&_=${listToken}`;
439
+ }
440
+
441
+ const { data } = await axios.get(requestUrl, { headers: buildHeaders() });
442
+ const $ = load(data.result);
443
+ const servers: IEpisodeServer[] = [];
444
+ const subOrDubKey = subOrDub === SubOrDubEnum.SUB ? 'softsub' : 'dub';
445
+
446
+ const serverItems = $(`.server-items.lang-group[data-id="${subOrDubKey}"] .server`);
447
+ await Promise.all(
448
+ serverItems.map(async (_, server) => {
449
+ const serverId = $(server).attr('data-lid');
450
+ if (!serverId) return;
451
+
452
+ const viewToken = await GenerateToken(serverId);
453
+ const { data: linkData } = await axios.get(`${config.baseUrl}/ajax/links/view?id=${serverId}&_=${viewToken}`, {
454
+ headers: buildHeaders(),
455
+ });
456
+ const decoded = await DecodeIframeData(linkData.result);
457
+
458
+ servers.push({
459
+ name: `MegaUp ${$(server).text().trim()}`.toLowerCase(),
460
+ url: decoded.url,
461
+ intro: {
462
+ start: decoded.skip.intro[0],
463
+ end: decoded.skip.intro[1],
464
+ },
465
+ outro: {
466
+ start: decoded.skip.outro[0],
467
+ end: decoded.skip.outro[1],
468
+ },
469
+ });
470
+ })
471
+ );
472
+
473
+ return servers;
474
+ };
475
+
476
+ const fetchEpisodeSources = async (
477
+ episodeId: string,
478
+ server: StreamingServers = StreamingServersEnum.MegaUp,
479
+ subOrDub: SubOrDub = SubOrDubEnum.SUB
480
+ ): Promise<ISource> => {
481
+ if (episodeId.startsWith('http')) {
482
+ const serverUrl = new PolyURL(episodeId);
483
+ switch (server) {
484
+ case StreamingServersEnum.MegaUp:
485
+ return {
486
+ headers: { Referer: serverUrl.href },
487
+ ...(await MegaUp().extract(serverUrl)),
488
+ download: serverUrl.href.replace(/\/e\//, '/download/'),
489
+ };
490
+ default:
491
+ return {
492
+ headers: { Referer: serverUrl.href },
493
+ ...(await MegaUp().extract(serverUrl)),
494
+ download: serverUrl.href.replace(/\/e\//, '/download/'),
495
+ };
496
+ }
497
+ }
498
+
499
+ try {
500
+ const servers = await fetchEpisodeServers(episodeId, subOrDub);
501
+ const i = servers.findIndex((s) => s.name.toLowerCase().includes(server)); //for now only megaup is available, hence directly using it
502
+
503
+ if (i === -1) {
504
+ throw new Error(`Server ${server} not found`);
505
+ }
506
+
507
+ const serverUrl: URL = new URL(servers[i]!.url);
508
+ const sources = await fetchEpisodeSources(serverUrl.href, server, subOrDub);
509
+ sources.intro = servers[i]?.intro as Intro;
510
+ sources.outro = servers[i]?.outro as Intro;
511
+ return sources;
512
+ } catch (err) {
513
+ throw new Error((err as Error).message);
514
+ }
515
+ };
516
+
517
+ const GenerateToken = async (text: string): Promise<string> => {
518
+ try {
519
+ const { data } = await axios.get(`${apiBase}/enc-kai`, {
520
+ params: { text },
521
+ });
522
+ return data.result;
523
+ } catch (error) {
524
+ throw new Error((error as Error).message);
525
+ }
526
+ };
527
+
528
+ const DecodeIframeData = async (
529
+ payload: string
530
+ ): Promise<{
531
+ url: string;
532
+ skip: {
533
+ intro: [number, number];
534
+ outro: [number, number];
535
+ };
536
+ }> => {
537
+ try {
538
+ const { data } = await axios.post(`${apiBase}/dec-kai`, { text: payload });
539
+ return data.result;
540
+ } catch (error) {
541
+ throw new Error((error as Error).message);
542
+ }
543
+ };
544
+
545
+ return {
546
+ name: config.name,
547
+ get baseUrl() {
548
+ return config.baseUrl;
549
+ },
550
+ set baseUrl(value: string) {
551
+ config.baseUrl = value.startsWith('http') ? value : `http://${value}`;
552
+ },
553
+ logo: config.logo,
554
+ classPath: config.classPath,
555
+
556
+ search,
557
+ fetchLatestCompleted,
558
+ fetchRecentlyAdded,
559
+ fetchRecentlyUpdated,
560
+ fetchNewReleases,
561
+ fetchMovie,
562
+ fetchTV,
563
+ fetchOVA,
564
+ fetchONA,
565
+ fetchSpecial,
566
+ fetchGenres,
567
+ genreSearch,
568
+ fetchSchedule,
569
+ fetchSpotlight,
570
+ fetchSearchSuggestions,
571
+ fetchAnimeInfo,
572
+ fetchEpisodeSources,
573
+ fetchEpisodeServers,
574
+ };
575
+ }
576
+
577
+ export type AnimeKaiProviderInstance = ReturnType<typeof createAnimeKai>;
578
+
579
+ export default createAnimeKai;
@@ -6,7 +6,8 @@ import AnimeDrive from './animedrive';
6
6
  import Anify from './anify';
7
7
  import Marin from './marin';
8
8
  import AnimeUnity from './animeunity';
9
- import AnimeKai from './animekai';
9
+ import AnimeKai from './animekai/animekai';
10
+ import createAnimeKai from './animekai/create-animekai';
10
11
 
11
12
  export default {
12
13
  AnimePahe,
@@ -18,4 +19,5 @@ export default {
18
19
  Marin,
19
20
  AnimeUnity,
20
21
  AnimeKai,
22
+ createAnimeKai,
21
23
  };
@@ -36,7 +36,7 @@ import {
36
36
  } from '../../utils';
37
37
  import Anify from '../anime/anify';
38
38
  import Zoro from '../anime/zoro/zoro';
39
- import AnimeKai from '../anime/animekai';
39
+ import AnimeKai from '../anime/animekai/animekai';
40
40
  import AnimePahe from '../anime/animepahe/animepahe';
41
41
  import Mangasee123 from '../manga/mangasee123';
42
42
  import { ANIFY_URL, findSimilarTitles, getHashFromImage } from '../../utils/utils';