react-native-consumet 1.2.3 → 1.3.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 (54) hide show
  1. package/lib/commonjs/extension-registry.json +27 -3
  2. package/lib/commonjs/extractors/megacloud.js +8 -35
  3. package/lib/commonjs/extractors/megacloud.js.map +1 -1
  4. package/lib/commonjs/providers/anime/aniwatchtv/aniwatchtv.js +187 -0
  5. package/lib/commonjs/providers/anime/aniwatchtv/aniwatchtv.js.map +1 -0
  6. package/lib/commonjs/providers/anime/aniwatchtv/create-aniwatchtv.js +572 -0
  7. package/lib/commonjs/providers/anime/aniwatchtv/create-aniwatchtv.js.map +1 -0
  8. package/lib/commonjs/providers/anime/index.js +5 -1
  9. package/lib/commonjs/providers/anime/index.js.map +1 -1
  10. package/lib/commonjs/providers/meta/anilist.js +2 -1
  11. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  12. package/lib/commonjs/utils/provider-maps.js +3 -0
  13. package/lib/commonjs/utils/provider-maps.js.map +1 -1
  14. package/lib/module/extension-registry.json +27 -3
  15. package/lib/module/extractors/megacloud.js +8 -35
  16. package/lib/module/extractors/megacloud.js.map +1 -1
  17. package/lib/module/providers/anime/aniwatchtv/aniwatchtv.js +184 -0
  18. package/lib/module/providers/anime/aniwatchtv/aniwatchtv.js.map +1 -0
  19. package/lib/module/providers/anime/aniwatchtv/create-aniwatchtv.js +569 -0
  20. package/lib/module/providers/anime/aniwatchtv/create-aniwatchtv.js.map +1 -0
  21. package/lib/module/providers/anime/index.js +5 -1
  22. package/lib/module/providers/anime/index.js.map +1 -1
  23. package/lib/module/providers/meta/anilist.js +2 -1
  24. package/lib/module/providers/meta/anilist.js.map +1 -1
  25. package/lib/module/utils/provider-maps.js +3 -0
  26. package/lib/module/utils/provider-maps.js.map +1 -1
  27. package/lib/typescript/commonjs/src/extractors/megacloud.d.ts.map +1 -1
  28. package/lib/typescript/commonjs/src/providers/anime/aniwatchtv/aniwatchtv.d.ts +134 -0
  29. package/lib/typescript/commonjs/src/providers/anime/aniwatchtv/aniwatchtv.d.ts.map +1 -0
  30. package/lib/typescript/commonjs/src/providers/anime/aniwatchtv/create-aniwatchtv.d.ts +49 -0
  31. package/lib/typescript/commonjs/src/providers/anime/aniwatchtv/create-aniwatchtv.d.ts.map +1 -0
  32. package/lib/typescript/commonjs/src/providers/anime/index.d.ts +4 -0
  33. package/lib/typescript/commonjs/src/providers/anime/index.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/src/utils/provider-maps.d.ts +1 -0
  36. package/lib/typescript/commonjs/src/utils/provider-maps.d.ts.map +1 -1
  37. package/lib/typescript/module/src/extractors/megacloud.d.ts.map +1 -1
  38. package/lib/typescript/module/src/providers/anime/aniwatchtv/aniwatchtv.d.ts +134 -0
  39. package/lib/typescript/module/src/providers/anime/aniwatchtv/aniwatchtv.d.ts.map +1 -0
  40. package/lib/typescript/module/src/providers/anime/aniwatchtv/create-aniwatchtv.d.ts +49 -0
  41. package/lib/typescript/module/src/providers/anime/aniwatchtv/create-aniwatchtv.d.ts.map +1 -0
  42. package/lib/typescript/module/src/providers/anime/index.d.ts +4 -0
  43. package/lib/typescript/module/src/providers/anime/index.d.ts.map +1 -1
  44. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  45. package/lib/typescript/module/src/utils/provider-maps.d.ts +1 -0
  46. package/lib/typescript/module/src/utils/provider-maps.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/extension-registry.json +27 -3
  49. package/src/extractors/megacloud.ts +7 -38
  50. package/src/providers/anime/aniwatchtv/aniwatchtv.ts +198 -0
  51. package/src/providers/anime/aniwatchtv/create-aniwatchtv.ts +632 -0
  52. package/src/providers/anime/index.ts +4 -0
  53. package/src/providers/meta/anilist.ts +7 -1
  54. package/src/utils/provider-maps.ts +3 -0
@@ -0,0 +1,632 @@
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 WatchListType,
12
+ type ProviderContext,
13
+ type ProviderConfig,
14
+ } from '../../../models';
15
+
16
+ function createAniWatchTv(ctx: ProviderContext, customBaseURL?: string) {
17
+ const { axios, load, extractors, enums, createCustomBaseUrl, PolyURL } = ctx;
18
+ const { StreamSB, MegaCloud, StreamTape } = extractors;
19
+ const {
20
+ StreamingServers: StreamingServersEnum,
21
+ SubOrDub: SubOrDubEnum,
22
+ MediaStatus: MediaStatusEnum,
23
+ WatchListType: WatchListTypeEnum,
24
+ } = enums;
25
+
26
+ // Provider configuration - use the standardized base URL creation
27
+ const baseUrl = createCustomBaseUrl('https://aniwatchtv.to', customBaseURL);
28
+
29
+ const config: ProviderConfig = {
30
+ name: 'AniWatchTv',
31
+ languages: 'en',
32
+ classPath: 'ANIME.AniWatchTv',
33
+ logo: 'https://aniwatchtv.to/favicon-32x32.png',
34
+ baseUrl,
35
+ isNSFW: false,
36
+ isWorking: true,
37
+ isDubAvailableSeparately: true,
38
+ };
39
+
40
+ // Helper functions
41
+ const normalizePageNumber = (page: number): number => {
42
+ return page <= 0 ? 1 : page;
43
+ };
44
+
45
+ // Main provider functions
46
+ const search = async (query: string, page: number = 1): Promise<ISearch<IAnimeResult>> => {
47
+ const normalizedPage = normalizePageNumber(page);
48
+ return scrapeCardPage(`${config.baseUrl}/search?keyword=${decodeURIComponent(query)}&page=${normalizedPage}`);
49
+ };
50
+
51
+ const fetchAdvancedSearch = async (
52
+ page: number = 1,
53
+ type?: string,
54
+ status?: string,
55
+ rated?: string,
56
+ score?: number,
57
+ season?: string,
58
+ language?: string,
59
+ startDate?: { year: number; month: number; day: number },
60
+ endDate?: { year: number; month: number; day: number },
61
+ sort?: string,
62
+ genres?: string[]
63
+ ): Promise<ISearch<IAnimeResult>> => {
64
+ const normalizedPage = normalizePageNumber(page);
65
+
66
+ const mappings = {
67
+ type: { movie: 1, tv: 2, ova: 3, ona: 4, special: 5, music: 6 },
68
+ status: { finished_airing: 1, currently_airing: 2, not_yet_aired: 3 },
69
+ rated: { g: 1, pg: 2, pg_13: 3, r: 4, r_plus: 5, rx: 6 },
70
+ season: { spring: 1, summer: 2, fall: 3, winter: 4 },
71
+ language: { sub: 1, dub: 2, sub_dub: 3 },
72
+ genre: {
73
+ action: 1,
74
+ adventure: 2,
75
+ cars: 3,
76
+ comedy: 4,
77
+ dementia: 5,
78
+ demons: 6,
79
+ mystery: 7,
80
+ drama: 8,
81
+ ecchi: 9,
82
+ fantasy: 10,
83
+ game: 11,
84
+ historical: 12,
85
+ horror: 13,
86
+ kids: 14,
87
+ magic: 15,
88
+ martial_arts: 16,
89
+ mecha: 17,
90
+ music: 18,
91
+ parody: 19,
92
+ samurai: 20,
93
+ romance: 21,
94
+ school: 22,
95
+ sci_fi: 23,
96
+ shoujo: 24,
97
+ shoujo_ai: 25,
98
+ shounen: 26,
99
+ shounen_ai: 27,
100
+ space: 28,
101
+ sports: 29,
102
+ super_power: 30,
103
+ vampire: 31,
104
+ harem: 32,
105
+ slice_of_life: 33,
106
+ supernatural: 34,
107
+ military: 35,
108
+ police: 36,
109
+ psychological: 37,
110
+ thriller: 38,
111
+ seinen: 39,
112
+ josei: 40,
113
+ isekai: 41,
114
+ },
115
+ };
116
+
117
+ const params = new URLSearchParams();
118
+ params.append('page', normalizedPage.toString());
119
+
120
+ if (type && mappings.type[type as keyof typeof mappings.type]) {
121
+ params.append('type', mappings.type[type as keyof typeof mappings.type].toString());
122
+ }
123
+ if (status && mappings.status[status as keyof typeof mappings.status]) {
124
+ params.append('status', mappings.status[status as keyof typeof mappings.status].toString());
125
+ }
126
+ if (rated && mappings.rated[rated as keyof typeof mappings.rated]) {
127
+ params.append('rated', mappings.rated[rated as keyof typeof mappings.rated].toString());
128
+ }
129
+ if (score) params.append('score', score.toString());
130
+ if (season && mappings.season[season as keyof typeof mappings.season]) {
131
+ params.append('season', mappings.season[season as keyof typeof mappings.season].toString());
132
+ }
133
+ if (language && mappings.language[language as keyof typeof mappings.language]) {
134
+ params.append('language', mappings.language[language as keyof typeof mappings.language].toString());
135
+ }
136
+ if (sort) params.append('sort', sort);
137
+
138
+ if (startDate) {
139
+ params.append(
140
+ 'start_date',
141
+ `${startDate.year}-${startDate.month.toString().padStart(2, '0')}-${startDate.day.toString().padStart(2, '0')}`
142
+ );
143
+ }
144
+ if (endDate) {
145
+ params.append(
146
+ 'end_date',
147
+ `${endDate.year}-${endDate.month.toString().padStart(2, '0')}-${endDate.day.toString().padStart(2, '0')}`
148
+ );
149
+ }
150
+
151
+ if (genres && genres.length > 0) {
152
+ const genreIds = genres.map((g) => mappings.genre[g as keyof typeof mappings.genre]).filter(Boolean);
153
+ if (genreIds.length > 0) {
154
+ params.append('genres', genreIds.join(','));
155
+ }
156
+ }
157
+
158
+ return scrapeCardPage(`${config.baseUrl}/filter?${params.toString()}`);
159
+ };
160
+
161
+ const fetchTopAiring = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
162
+ const normalizedPage = normalizePageNumber(page);
163
+ return scrapeCardPage(`${config.baseUrl}/top-airing?page=${normalizedPage}`);
164
+ };
165
+
166
+ const fetchMostPopular = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
167
+ const normalizedPage = normalizePageNumber(page);
168
+ return scrapeCardPage(`${config.baseUrl}/most-popular?page=${normalizedPage}`);
169
+ };
170
+
171
+ const fetchMostFavorite = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
172
+ const normalizedPage = normalizePageNumber(page);
173
+ return scrapeCardPage(`${config.baseUrl}/most-favorite?page=${normalizedPage}`);
174
+ };
175
+
176
+ const fetchLatestCompleted = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
177
+ const normalizedPage = normalizePageNumber(page);
178
+ return scrapeCardPage(`${config.baseUrl}/completed?page=${normalizedPage}`);
179
+ };
180
+
181
+ const fetchRecentlyUpdated = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
182
+ const normalizedPage = normalizePageNumber(page);
183
+ return scrapeCardPage(`${config.baseUrl}/recently-updated?page=${normalizedPage}`);
184
+ };
185
+
186
+ const fetchRecentlyAdded = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
187
+ const normalizedPage = normalizePageNumber(page);
188
+ return scrapeCardPage(`${config.baseUrl}/recently-added?page=${normalizedPage}`);
189
+ };
190
+
191
+ const fetchTopUpcoming = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
192
+ const normalizedPage = normalizePageNumber(page);
193
+ return scrapeCardPage(`${config.baseUrl}/top-upcoming?page=${normalizedPage}`);
194
+ };
195
+
196
+ const fetchStudio = async (studio: string, page: number = 1): Promise<ISearch<IAnimeResult>> => {
197
+ const normalizedPage = normalizePageNumber(page);
198
+ return scrapeCardPage(`${config.baseUrl}/producer/${studio}?page=${normalizedPage}`);
199
+ };
200
+
201
+ const fetchSubbedAnime = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
202
+ const normalizedPage = normalizePageNumber(page);
203
+ return scrapeCardPage(`${config.baseUrl}/subbed-anime?page=${normalizedPage}`);
204
+ };
205
+
206
+ const fetchDubbedAnime = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
207
+ const normalizedPage = normalizePageNumber(page);
208
+ return scrapeCardPage(`${config.baseUrl}/dubbed-anime?page=${normalizedPage}`);
209
+ };
210
+
211
+ const fetchMovie = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
212
+ const normalizedPage = normalizePageNumber(page);
213
+ return scrapeCardPage(`${config.baseUrl}/movie?page=${normalizedPage}`);
214
+ };
215
+
216
+ const fetchTV = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
217
+ const normalizedPage = normalizePageNumber(page);
218
+ return scrapeCardPage(`${config.baseUrl}/tv?page=${normalizedPage}`);
219
+ };
220
+
221
+ const fetchOVA = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
222
+ const normalizedPage = normalizePageNumber(page);
223
+ return scrapeCardPage(`${config.baseUrl}/ova?page=${normalizedPage}`);
224
+ };
225
+
226
+ const fetchONA = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
227
+ const normalizedPage = normalizePageNumber(page);
228
+ return scrapeCardPage(`${config.baseUrl}/ona?page=${normalizedPage}`);
229
+ };
230
+
231
+ const fetchSpecial = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
232
+ const normalizedPage = normalizePageNumber(page);
233
+ return scrapeCardPage(`${config.baseUrl}/special?page=${normalizedPage}`);
234
+ };
235
+
236
+ const fetchGenres = async (page: number = 1): Promise<ISearch<IAnimeResult>> => {
237
+ const normalizedPage = normalizePageNumber(page);
238
+ return scrapeCardPage(`${config.baseUrl}/genre?page=${normalizedPage}`);
239
+ };
240
+
241
+ const genreSearch = async (genre: string, page: number = 1): Promise<ISearch<IAnimeResult>> => {
242
+ const normalizedPage = normalizePageNumber(page);
243
+ return scrapeCardPage(`${config.baseUrl}/genre/${genre}?page=${normalizedPage}`);
244
+ };
245
+
246
+ const fetchSchedule = async (date: string): Promise<IAnimeResult[]> => {
247
+ try {
248
+ const response = await fetch(`${config.baseUrl}/ajax/schedule/list?tzOffset=-330&date=${date}`);
249
+ const data = await response.json();
250
+ const $ = load(data.html);
251
+
252
+ return await scrapeCard($);
253
+ } catch (error) {
254
+ throw new Error(`Failed to fetch schedule: ${error}`);
255
+ }
256
+ };
257
+
258
+ const fetchSpotlight = async (): Promise<IAnimeResult[]> => {
259
+ try {
260
+ const response = await fetch(config.baseUrl);
261
+ const data = await response.text();
262
+ const $ = load(data);
263
+
264
+ const results: IAnimeResult[] = [];
265
+
266
+ $('.deslide-item').each((_, element) => {
267
+ const id = $(element).find('a').attr('href')?.split('/')[1] || '';
268
+ const title = $(element).find('.desi-head-title').text().trim();
269
+ const poster =
270
+ $(element)
271
+ .find('.desi-buttons-wrap .btn-secondary')
272
+ .attr('href')
273
+ ?.match(/url=([^&]+)/)?.[1] || '';
274
+ const description = $(element).find('.desi-description').text().trim();
275
+
276
+ if (id) {
277
+ results.push({
278
+ id,
279
+ title,
280
+ url: `${config.baseUrl}/${id}`,
281
+ image: decodeURIComponent(poster),
282
+ description,
283
+ });
284
+ }
285
+ });
286
+
287
+ return results;
288
+ } catch (error) {
289
+ throw new Error(`Failed to fetch spotlight: ${error}`);
290
+ }
291
+ };
292
+
293
+ const fetchSearchSuggestions = async (query: string): Promise<IAnimeResult[]> => {
294
+ try {
295
+ const response = await fetch(`${config.baseUrl}/ajax/search/suggest?keyword=${encodeURIComponent(query)}`);
296
+ const data = await response.json();
297
+ const $ = load(data.html);
298
+
299
+ return await scrapeCard($);
300
+ } catch (error) {
301
+ throw new Error(`Failed to fetch search suggestions: ${error}`);
302
+ }
303
+ };
304
+
305
+ const fetchContinueWatching = async (): Promise<IAnimeResult[]> => {
306
+ try {
307
+ const response = await fetch(`${config.baseUrl}/ajax/home/widget/continue-watching`);
308
+ const data = await response.json();
309
+ const $ = load(data.html);
310
+
311
+ return await scrapeCard($);
312
+ } catch (error) {
313
+ throw new Error(`Failed to fetch continue watching: ${error}`);
314
+ }
315
+ };
316
+
317
+ const fetchWatchList = async (watchListType: WatchListType): Promise<IAnimeResult[]> => {
318
+ try {
319
+ const response = await fetch(`${config.baseUrl}/ajax/user/watchlist/${watchListType}`);
320
+ const data = await response.json();
321
+ const $ = load(data.html);
322
+
323
+ return await scrapeCard($);
324
+ } catch (error) {
325
+ throw new Error(`Failed to fetch watch list: ${error}`);
326
+ }
327
+ };
328
+
329
+ const fetchAnimeInfo = async (id: string): Promise<IAnimeInfo> => {
330
+ try {
331
+ const animeUrl = `${config.baseUrl}/${id}`;
332
+ const response = await fetch(animeUrl);
333
+ const data = await response.text();
334
+ const $ = load(data);
335
+
336
+ const info: IAnimeInfo = {
337
+ id: id,
338
+ title: $('.anisc-detail h2.film-name').text().trim(),
339
+ url: animeUrl,
340
+ genres: [],
341
+ totalEpisodes: 0,
342
+ };
343
+
344
+ info.image = $('.film-poster img').attr('src');
345
+ info.description = $('.film-description .text').text().trim();
346
+
347
+ // Extract genres
348
+ $('.item-list a[href*="/genre/"]').each((_, el) => {
349
+ info.genres?.push($(el).text().trim());
350
+ });
351
+
352
+ // Extract other info from the info list
353
+ $('.anisc-info .item').each((_, item) => {
354
+ const label = $(item).find('.item-head').text().trim().toLowerCase();
355
+ const value =
356
+ $(item).find('.name').text().trim() || $(item).text().replace($(item).find('.item-head').text(), '').trim();
357
+
358
+ if (label.includes('studio')) info.studios = [value];
359
+ if (label.includes('duration')) info.duration = value;
360
+ if (label.includes('status')) {
361
+ switch (value) {
362
+ case 'Finished Airing':
363
+ info.status = MediaStatusEnum.COMPLETED;
364
+ break;
365
+ case 'Currently Airing':
366
+ info.status = MediaStatusEnum.ONGOING;
367
+ break;
368
+ case 'Not yet aired':
369
+ info.status = MediaStatusEnum.NOT_YET_AIRED;
370
+ break;
371
+ default:
372
+ info.status = MediaStatusEnum.UNKNOWN;
373
+ break;
374
+ }
375
+ }
376
+ if (label.includes('type')) info.type = value as MediaFormat;
377
+ if (label.includes('score')) info.rating = parseFloat(value);
378
+ if (label.includes('premiered')) info.releaseDate = value;
379
+ if (label.includes('japanese')) info.japaneseTitle = value;
380
+ });
381
+
382
+ // Check for sub/dub availability
383
+ const hasSub: boolean = $('div.film-stats div.tick div.tick-item.tick-sub').length > 0;
384
+ const hasDub: boolean = $('div.film-stats div.tick div.tick-item.tick-dub').length > 0;
385
+
386
+ if (hasSub) {
387
+ info.subOrDub = SubOrDubEnum.SUB;
388
+ info.hasSub = hasSub;
389
+ }
390
+ if (hasDub) {
391
+ info.subOrDub = SubOrDubEnum.DUB;
392
+ info.hasDub = hasDub;
393
+ }
394
+ if (hasSub && hasDub) {
395
+ info.subOrDub = SubOrDubEnum.BOTH;
396
+ }
397
+
398
+ // Fetch episodes
399
+ const episodesResponse = await fetch(`${config.baseUrl}/ajax/v2/episode/list/${id.split('-').pop()}`, {
400
+ headers: {
401
+ 'X-Requested-With': 'XMLHttpRequest',
402
+ 'Referer': `${config.baseUrl}/watch/${id}`,
403
+ },
404
+ });
405
+ const episodesData = await episodesResponse.json();
406
+ const $$ = load(episodesData.html);
407
+
408
+ const episodeElements = $$('div.detail-infor-content > div > a');
409
+ const subCount = parseInt($('div.film-stats div.tick div.tick-item.tick-sub').text().trim()) || 0;
410
+ const dubCount = parseInt($('div.film-stats div.tick div.tick-item.tick-dub').text().trim()) || 0;
411
+
412
+ info.totalEpisodes = episodeElements.length;
413
+ info.episodes = [];
414
+
415
+ episodeElements.each((i, el) => {
416
+ const $el = $$(el);
417
+ const href = $el.attr('href') || '';
418
+ const number = parseInt($el.attr('data-number') || '0');
419
+
420
+ info.episodes?.push({
421
+ id: href.split('/')[2]?.replace('?ep=', '$episode$') || '',
422
+ number: number,
423
+ title: $el.attr('title'),
424
+ isFiller: $el.hasClass('ssl-item-filler'),
425
+ isSubbed: number <= subCount,
426
+ isDubbed: number <= dubCount,
427
+ url: config.baseUrl + href,
428
+ });
429
+ });
430
+
431
+ return info;
432
+ } catch (err) {
433
+ throw new Error((err as Error).message);
434
+ }
435
+ };
436
+
437
+ const fetchEpisodeSources = async (
438
+ episodeId: string,
439
+ server: StreamingServers = StreamingServersEnum.MegaCloud,
440
+ subOrDub: SubOrDub = SubOrDubEnum.SUB
441
+ ): Promise<ISource> => {
442
+ if (episodeId.startsWith('http')) {
443
+ const serverUrl = new PolyURL(episodeId);
444
+ switch (server) {
445
+ case StreamingServersEnum.MegaCloud:
446
+ return {
447
+ headers: { Referer: serverUrl.href },
448
+ ...(await MegaCloud().extract(serverUrl, config.baseUrl)),
449
+ };
450
+ default:
451
+ return {
452
+ headers: { Referer: serverUrl.href },
453
+ ...(await MegaCloud().extract(serverUrl, config.baseUrl)),
454
+ };
455
+ }
456
+ }
457
+ if (!episodeId.includes('$episode$')) throw new Error('Invalid episode id');
458
+
459
+ episodeId = `${config.baseUrl}/watch/${episodeId.replace('$episode$', '?ep=').replace(/\$auto|\$sub|\$dub/gi, '')}`;
460
+ try {
461
+ const servers = await fetchEpisodeServers(episodeId.split('?ep=')[1]!, subOrDub);
462
+ const i = servers.findIndex((s) => s.name.toLowerCase().includes(server));
463
+ if (i === -1) {
464
+ throw new Error(`Server ${server} not found`);
465
+ }
466
+
467
+ const serverUrl: URL = new URL(servers[i]!.url);
468
+
469
+ return await fetchEpisodeSources(serverUrl.href, server, SubOrDubEnum.SUB);
470
+ } catch (err) {
471
+ throw err;
472
+ }
473
+ };
474
+
475
+ const fetchEpisodeServers = async (episodeId: string, subOrDub: SubOrDub): Promise<IEpisodeServer[]> => {
476
+ try {
477
+ if (episodeId.includes('$episode$')) episodeId = episodeId.split('$episode$')[1]!;
478
+ const response = await fetch(`${config.baseUrl}/ajax/v2/episode/servers?episodeId=${episodeId}`);
479
+ const data = await response.json();
480
+ const $ = load(data.html);
481
+ const scrapedServers: any[] = [];
482
+ let selector;
483
+ try {
484
+ selector = `.ps_-block.ps_-block-sub.servers-${false ? 'raw' : subOrDub} > .ps__-list .server-item`;
485
+ } catch {
486
+ selector = `.ps_-block.ps_-block-sub.servers-${true ? 'raw' : subOrDub} > .ps__-list .server-item`;
487
+ }
488
+ $(selector).each((_, element) => {
489
+ const name = $(element).text().trim();
490
+ const sourcesId = $(element).attr('data-id') || '';
491
+ const subOrDubValue = $(element).attr('data-type') === 'sub' ? SubOrDubEnum.SUB : SubOrDubEnum.DUB;
492
+
493
+ scrapedServers.push({
494
+ name,
495
+ sourcesId,
496
+ subOrDub: subOrDubValue,
497
+ });
498
+ });
499
+ const servers: IEpisodeServer[] = await Promise.all(
500
+ scrapedServers.map(async (server) => {
501
+ const { data } = await axios.get(`https://aniwatchtv.to/ajax/v2/episode/sources?id=${server.sourcesId}`);
502
+ return {
503
+ name: `megacloud-${server.name.toLowerCase()}`,
504
+ url: data.link,
505
+ };
506
+ })
507
+ );
508
+ return servers;
509
+ } catch (error) {
510
+ throw new Error(`Failed to fetch episode servers: ${error}`);
511
+ }
512
+ };
513
+
514
+ const scrapeCard = async ($: CheerioAPI): Promise<IAnimeResult[]> => {
515
+ try {
516
+ const results: IAnimeResult[] = [];
517
+
518
+ $('.flw-item').each((i, ele) => {
519
+ const card = $(ele);
520
+ const atag = card.find('.film-name a');
521
+ const id = atag.attr('href')?.split('/')[1]!.split('?')[0];
522
+ const watchList = card.find('.dropdown-menu .added').text().trim() as WatchListType;
523
+ const typeTexts = card
524
+ .find('.fdi-item')
525
+ .map((_, el) => $(el).text().trim())
526
+ .get();
527
+ const type = typeTexts[0] || 'Unknown';
528
+
529
+ results.push({
530
+ id: id!,
531
+ title: atag.text().trim(),
532
+ url: `${config.baseUrl}${atag.attr('href')}`,
533
+ image: card.find('img').attr('data-src') || card.find('img').attr('src'),
534
+ duration: card.find('.fdi-duration').text().trim(),
535
+ watchList: watchList || WatchListTypeEnum.NONE,
536
+ japaneseTitle: atag.attr('data-jname'),
537
+ type: type as MediaFormat,
538
+ nsfw: card.find('.tick-rate').text().trim() === '18+' ? true : false,
539
+ sub: parseInt(card.find('.tick-item.tick-sub').text().trim(), 10) || 0,
540
+ dub: parseInt(card.find('.tick-item.tick-dub').text().trim(), 10) || 0,
541
+ episodes: parseInt(card.find('.tick-item.tick-eps').text().trim(), 10) || 0,
542
+ });
543
+ });
544
+ return results;
545
+ } catch (err) {
546
+ //console.log(err);
547
+ throw new Error(`Failed to scrape card: ${err}`);
548
+ }
549
+ };
550
+
551
+ const scrapeCardPage = async (url: string, headers?: object): Promise<ISearch<IAnimeResult>> => {
552
+ try {
553
+ const res: ISearch<IAnimeResult> = {
554
+ currentPage: 0,
555
+ hasNextPage: false,
556
+ totalPages: 0,
557
+ results: [],
558
+ };
559
+ const response = await fetch(url, headers);
560
+
561
+ if (!response.ok) {
562
+ throw new Error(`HTTP ${response.status} ${response.statusText} for ${url}`);
563
+ }
564
+
565
+ const data = await response.text();
566
+ const $ = load(data);
567
+
568
+ const pagination = $('ul.pagination');
569
+ res.currentPage = parseInt(pagination.find('.page-item.active').text().trim(), 10) || 1;
570
+ const nextPage = pagination.find('a[title=Next]').attr('href');
571
+ if (nextPage !== undefined && nextPage !== '') {
572
+ res.hasNextPage = true;
573
+ }
574
+ const totalPages = pagination.find('a[title=Last]').attr('href')?.split('=').pop();
575
+ if (totalPages === undefined || totalPages === '') {
576
+ res.totalPages = res.currentPage;
577
+ } else {
578
+ res.totalPages = parseInt(totalPages, 10);
579
+ }
580
+
581
+ res.results = await scrapeCard($);
582
+ if (res.results.length === 0) {
583
+ res.currentPage = 0;
584
+ res.hasNextPage = false;
585
+ res.totalPages = 0;
586
+ }
587
+ return res;
588
+ } catch (err) {
589
+ console.error('scrapeCardPage error:', err);
590
+ throw new Error(`Failed to scrape page ${url}: ${err instanceof Error ? err.message : 'Unknown error'}`);
591
+ }
592
+ };
593
+
594
+ // Return the functional provider object
595
+ return {
596
+ ...config,
597
+ // Core methods, pass only the necessary methods, dont pass helpers or unused methods
598
+ search,
599
+ fetchAdvancedSearch,
600
+ fetchTopAiring,
601
+ fetchMostPopular,
602
+ fetchMostFavorite,
603
+ fetchLatestCompleted,
604
+ fetchRecentlyUpdated,
605
+ fetchRecentlyAdded,
606
+ fetchTopUpcoming,
607
+ fetchStudio,
608
+ fetchSubbedAnime,
609
+ fetchDubbedAnime,
610
+ fetchMovie,
611
+ fetchTV,
612
+ fetchOVA,
613
+ fetchONA,
614
+ fetchSpecial,
615
+ fetchGenres,
616
+ genreSearch,
617
+ fetchSchedule,
618
+ fetchSpotlight,
619
+ fetchSearchSuggestions,
620
+ fetchContinueWatching,
621
+ fetchWatchList,
622
+ fetchAnimeInfo,
623
+ fetchEpisodeSources,
624
+ fetchEpisodeServers,
625
+ };
626
+ }
627
+
628
+ // Type definition for the provider instance returned by createAniWatchTv
629
+ export type AniWatchTvProviderInstance = ReturnType<typeof createAniWatchTv>;
630
+
631
+ // Default export for backward compatibility
632
+ export default createAniWatchTv;
@@ -8,6 +8,8 @@ import Marin from './marin';
8
8
  import AnimeUnity from './animeunity';
9
9
  import AnimeKai from './animekai/animekai';
10
10
  import createAnimeKai from './animekai/create-animekai';
11
+ import AniWatchTv from './aniwatchtv/aniwatchtv';
12
+ import createAniWatchTv from './aniwatchtv/create-aniwatchtv';
11
13
 
12
14
  export default {
13
15
  AnimePahe,
@@ -20,4 +22,6 @@ export default {
20
22
  AnimeUnity,
21
23
  AnimeKai,
22
24
  createAnimeKai,
25
+ AniWatchTv,
26
+ createAniWatchTv,
23
27
  };
@@ -38,6 +38,7 @@ import Anify from '../anime/anify';
38
38
  import Zoro from '../anime/zoro/zoro';
39
39
  import AnimeKai from '../anime/animekai/animekai';
40
40
  import AnimePahe from '../anime/animepahe/animepahe';
41
+ import AniWatchTv from '../anime/aniwatchtv/aniwatchtv';
41
42
  import Mangasee123 from '../manga/mangasee123';
42
43
  import { ANIFY_URL, findSimilarTitles, getHashFromImage } from '../../utils/utils';
43
44
 
@@ -1145,7 +1146,12 @@ class Anilist extends AnimeParser {
1145
1146
 
1146
1147
  let possibleAnimeEpisodes: IAnimeEpisode[] = [];
1147
1148
  let fillerEpisodes: { 'number': string; 'filler-bool': boolean }[] = [];
1148
- if (this.provider instanceof Zoro || this.provider instanceof AnimeKai || this.provider instanceof AnimePahe) {
1149
+ if (
1150
+ this.provider instanceof Zoro ||
1151
+ this.provider instanceof AnimeKai ||
1152
+ this.provider instanceof AnimePahe ||
1153
+ this.provider instanceof AniWatchTv
1154
+ ) {
1149
1155
  try {
1150
1156
  // console.time('fetchEpisodesListById');
1151
1157
  const [animeMetaData, providerEpisodes] = await Promise.all([
@@ -20,6 +20,9 @@ export const animeProviders = {
20
20
  get AnimeKai() {
21
21
  return require('../providers/anime/animekai/animekai').default;
22
22
  },
23
+ get AniWatchTv() {
24
+ return require('../providers/anime/aniwatchtv/aniwatchtv').default;
25
+ },
23
26
  };
24
27
 
25
28
  export const movieProviders = {