react-native-consumet 0.8.0 → 0.9.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 (95) hide show
  1. package/Consumet.podspec +26 -26
  2. package/LICENSE +673 -673
  3. package/README.md +49 -49
  4. package/android/build.gradle +106 -106
  5. package/android/gradle.properties +5 -5
  6. package/android/src/main/AndroidManifest.xml +4 -4
  7. package/android/src/main/AndroidManifestNew.xml +3 -3
  8. package/android/src/main/java/com/consumet/ConsumetModule.kt +49 -49
  9. package/android/src/main/java/com/consumet/ConsumetPackage.kt +33 -33
  10. package/ios/Consumet.h +6 -6
  11. package/ios/Consumet.mm +18 -18
  12. package/lib/commonjs/extractors/megacloud/index.js +5 -0
  13. package/lib/commonjs/extractors/megacloud/index.js.map +1 -1
  14. package/lib/commonjs/extractors/megacloud/megacloud.getsrcs.js +73 -42
  15. package/lib/commonjs/extractors/megacloud/megacloud.getsrcs.js.map +1 -1
  16. package/lib/commonjs/extractors/vidcloud.js +37 -26
  17. package/lib/commonjs/extractors/vidcloud.js.map +1 -1
  18. package/lib/commonjs/models/types.js +1 -0
  19. package/lib/commonjs/models/types.js.map +1 -1
  20. package/lib/commonjs/providers/meta/anilist.js +22 -7
  21. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  22. package/lib/commonjs/providers/movies/index.js +3 -1
  23. package/lib/commonjs/providers/movies/index.js.map +1 -1
  24. package/lib/commonjs/providers/movies/multistream/index.js +208 -0
  25. package/lib/commonjs/providers/movies/multistream/index.js.map +1 -0
  26. package/lib/commonjs/providers/movies/multistream/utils.js +267 -0
  27. package/lib/commonjs/providers/movies/multistream/utils.js.map +1 -0
  28. package/lib/commonjs/providers/movies/netflixmirror.js +2 -2
  29. package/lib/commonjs/providers/movies/netflixmirror.js.map +1 -1
  30. package/lib/commonjs/utils/utils.js +58 -34
  31. package/lib/commonjs/utils/utils.js.map +1 -1
  32. package/lib/module/extractors/megacloud/index.js +5 -0
  33. package/lib/module/extractors/megacloud/index.js.map +1 -1
  34. package/lib/module/extractors/megacloud/megacloud.getsrcs.js +73 -42
  35. package/lib/module/extractors/megacloud/megacloud.getsrcs.js.map +1 -1
  36. package/lib/module/extractors/vidcloud.js +36 -26
  37. package/lib/module/extractors/vidcloud.js.map +1 -1
  38. package/lib/module/models/types.js +1 -0
  39. package/lib/module/models/types.js.map +1 -1
  40. package/lib/module/providers/meta/anilist.js +22 -7
  41. package/lib/module/providers/meta/anilist.js.map +1 -1
  42. package/lib/module/providers/movies/index.js +3 -1
  43. package/lib/module/providers/movies/index.js.map +1 -1
  44. package/lib/module/providers/movies/multistream/index.js +205 -0
  45. package/lib/module/providers/movies/multistream/index.js.map +1 -0
  46. package/lib/module/providers/movies/multistream/utils.js +259 -0
  47. package/lib/module/providers/movies/multistream/utils.js.map +1 -0
  48. package/lib/module/providers/movies/netflixmirror.js +2 -2
  49. package/lib/module/providers/movies/netflixmirror.js.map +1 -1
  50. package/lib/module/utils/utils.js +55 -30
  51. package/lib/module/utils/utils.js.map +1 -1
  52. package/lib/typescript/commonjs/src/extractors/megacloud/index.d.ts.map +1 -1
  53. package/lib/typescript/commonjs/src/extractors/megacloud/megacloud.getsrcs.d.ts +3 -4
  54. package/lib/typescript/commonjs/src/extractors/megacloud/megacloud.getsrcs.d.ts.map +1 -1
  55. package/lib/typescript/commonjs/src/extractors/vidcloud.d.ts.map +1 -1
  56. package/lib/typescript/commonjs/src/models/types.d.ts +2 -1
  57. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  58. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  59. package/lib/typescript/commonjs/src/providers/movies/index.d.ts +2 -0
  60. package/lib/typescript/commonjs/src/providers/movies/index.d.ts.map +1 -1
  61. package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts +37 -0
  62. package/lib/typescript/commonjs/src/providers/movies/multistream/index.d.ts.map +1 -0
  63. package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts +10 -0
  64. package/lib/typescript/commonjs/src/providers/movies/multistream/utils.d.ts.map +1 -0
  65. package/lib/typescript/commonjs/src/providers/movies/netflixmirror.d.ts.map +1 -1
  66. package/lib/typescript/commonjs/src/utils/utils.d.ts +8 -8
  67. package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -1
  68. package/lib/typescript/module/src/extractors/megacloud/index.d.ts.map +1 -1
  69. package/lib/typescript/module/src/extractors/megacloud/megacloud.getsrcs.d.ts +3 -4
  70. package/lib/typescript/module/src/extractors/megacloud/megacloud.getsrcs.d.ts.map +1 -1
  71. package/lib/typescript/module/src/extractors/vidcloud.d.ts.map +1 -1
  72. package/lib/typescript/module/src/models/types.d.ts +2 -1
  73. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  74. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  75. package/lib/typescript/module/src/providers/movies/index.d.ts +2 -0
  76. package/lib/typescript/module/src/providers/movies/index.d.ts.map +1 -1
  77. package/lib/typescript/module/src/providers/movies/multistream/index.d.ts +37 -0
  78. package/lib/typescript/module/src/providers/movies/multistream/index.d.ts.map +1 -0
  79. package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts +10 -0
  80. package/lib/typescript/module/src/providers/movies/multistream/utils.d.ts.map +1 -0
  81. package/lib/typescript/module/src/providers/movies/netflixmirror.d.ts.map +1 -1
  82. package/lib/typescript/module/src/utils/utils.d.ts +8 -8
  83. package/lib/typescript/module/src/utils/utils.d.ts.map +1 -1
  84. package/package.json +3 -2
  85. package/react-native.config.js +12 -12
  86. package/src/extractors/megacloud/index.ts +7 -0
  87. package/src/extractors/megacloud/megacloud.getsrcs.ts +80 -39
  88. package/src/extractors/vidcloud.ts +37 -26
  89. package/src/models/types.ts +1 -0
  90. package/src/providers/meta/anilist.ts +20 -7
  91. package/src/providers/movies/index.ts +2 -0
  92. package/src/providers/movies/multistream/index.ts +232 -0
  93. package/src/providers/movies/multistream/utils.ts +393 -0
  94. package/src/providers/movies/netflixmirror.ts +2 -2
  95. package/src/utils/utils.ts +66 -31
@@ -0,0 +1,393 @@
1
+ import axios from 'axios';
2
+ import type { IEpisodeServer, ISource, ISubtitle, IVideo } from '../../../models';
3
+ import { USER_AGENT } from '../../../utils';
4
+ import { filterValidM3U8 } from '../../../utils/utils';
5
+ import { load } from 'cheerio';
6
+
7
+ export async function getRiveSourcesAndServers(id: string): Promise<ISource & { servers: IEpisodeServer[] }> {
8
+ const parts = id.split('$');
9
+ const [tmdbId, type, episode, season] = parts;
10
+ const secret = generateSecretKey(Number(tmdbId));
11
+ const riveServers = [
12
+ 'flowcast',
13
+ 'primevids',
14
+ 'loki',
15
+ 'shadow',
16
+ 'asiacloud',
17
+ 'hindicast',
18
+ 'anime',
19
+ 'animez',
20
+ 'sapphire',
21
+ 'guru',
22
+ 'guard',
23
+ 'curve',
24
+ 'hq',
25
+ 'ninja',
26
+ 'alpha',
27
+ 'kaze',
28
+ 'zenesis',
29
+ 'genesis',
30
+ 'zenith',
31
+ 'ghost',
32
+ 'halo',
33
+ 'kinoecho',
34
+ 'ee3',
35
+ 'volt',
36
+ 'putafilme',
37
+ 'ophim',
38
+ 'kage',
39
+ ];
40
+ const baseUrl = 'https://rivestream.org';
41
+ const route =
42
+ type === 'tv'
43
+ ? `/api/backendfetch?requestID=tvVideoProvider&id=${tmdbId}&season=${season}&episode=${episode}&secretKey=${secret}&service=`
44
+ : `/api/backendfetch?requestID=movieVideoProvider&id=${tmdbId}&secretKey=${secret}&service=`;
45
+ const url = baseUrl + route;
46
+ const subtitles: ISubtitle[] = [];
47
+ const sources: IVideo[] = [];
48
+ const servers: IEpisodeServer[] = [];
49
+ await Promise.all(
50
+ riveServers.map(async (server) => {
51
+ // console.log('Rive: ' + url + server);
52
+ try {
53
+ const res = await axios.get(url + server, {
54
+ timeout: 4000,
55
+ headers: {
56
+ 'Referer': baseUrl,
57
+ 'User-Agent': USER_AGENT,
58
+ },
59
+ });
60
+
61
+ if (res.data?.data?.captions) {
62
+ res.data?.data?.captions.forEach((sub: any) => {
63
+ subtitles.push({
64
+ lang: sub?.label?.slice(0, 2) || 'Und',
65
+ url: sub?.file,
66
+ });
67
+ });
68
+ }
69
+
70
+ res.data?.data?.sources.forEach((source: IVideo) => {
71
+ servers.push({
72
+ name: source?.source + '-' + source?.quality,
73
+ url: source?.url,
74
+ });
75
+ sources.push({
76
+ url: source?.url,
77
+ isM3U8: source?.format === 'hls' ? true : false,
78
+ quality: source?.quality,
79
+ name: source?.source + '-' + source?.quality,
80
+ });
81
+ });
82
+ } catch (e) {
83
+ // console.log(e);
84
+ return null;
85
+ }
86
+ })
87
+ );
88
+ const validUrls = await filterValidM3U8(sources.map((s) => s.url));
89
+ return {
90
+ sources: sources.filter((source) => validUrls.includes(source.url)),
91
+ subtitles: subtitles.filter((sub) => sub.url && sub.lang),
92
+ servers: servers.filter((source) => validUrls.includes(source.url)),
93
+ };
94
+ }
95
+
96
+ function generateSecretKey(id: number | string) {
97
+ // Array of secret key fragments - updated array from the new implementation
98
+ const c = [
99
+ 'oYRu3JJ5g1C',
100
+ 'TRlWJIJXT',
101
+ 'RuoyGA0udvsFVXr',
102
+ 'Y4s2LNM4y',
103
+ 'wHzuSgl0fD',
104
+ 'MGLTaSGs',
105
+ 'rr0rSBIYfwutV7E',
106
+ 'ABJXC9c',
107
+ 'W2BuY0yDB9CcK',
108
+ '3yvZP1OJuTM',
109
+ 'YDoqbu6zdN0zT',
110
+ 'rnNQ2a5OBaMu',
111
+ 'eSKa1Uy',
112
+ 'QsIV8J472Xa',
113
+ 'cPfTgu27',
114
+ 'j4mzadQCou9',
115
+ 'qHLZbLrZQfB',
116
+ '8U9YP6hrTz4cJNQ',
117
+ 'xbAbu4pzFEXz',
118
+ 'dhuA9zvdw',
119
+ 'k3A1JGmb',
120
+ 'eVC3z4COdUNvvzA',
121
+ 'dwMmuXnrb',
122
+ 'AqpWzY9I1ZmGPR',
123
+ 'VGXWUm0JTetmXs',
124
+ 'gD4sH3CISTanpTs',
125
+ 'd6w8dntV',
126
+ 'iL6dvSNqEab4kd',
127
+ 'mIB8NFtmPjnX1kM',
128
+ 'F4PXdP0Hx3',
129
+ '5Fijua4Z7C',
130
+ 'wPGnHJrkYa1Tu4P',
131
+ 'pjrfBfTf',
132
+ 'vswQDEbM0y64io',
133
+ 'LAnpQuk6hR2bEWs',
134
+ 'kX8orxNnkK',
135
+ 'mRsZ5fjHbC8YuT',
136
+ 'JnBr1jr',
137
+ '2twFGU5PgvDmKdP',
138
+ '3wCg6zYtHFjy',
139
+ 'gaQSJhixHiy1pa8',
140
+ 'pE2cXTP0GPX',
141
+ 'xr0ONW3sOnCRdt',
142
+ 'QZu43flHFsebX',
143
+ 'yrvtqRTOnHo',
144
+ 'kvXEs16lgj',
145
+ 'AGwT2zpQVHCMb09',
146
+ 'M4BxOh3z2JgC',
147
+ '5hbV7briYC7',
148
+ 'YfHMsm0',
149
+ 'jC9PAPfz34Vgc',
150
+ 'ExoJ1tgEXpK',
151
+ 'eD8WPA4Lmsyf4W',
152
+ 'h7WSlhT7iNOj',
153
+ 'RRP61kk',
154
+ 'QtY0f1aN',
155
+ 'TlatGjcOQjup',
156
+ 'MfpeEGbjouYSOa',
157
+ 'Zz0Qh8B0pwUkdRT',
158
+ 'Y4SkLSQNU',
159
+ 'hOk01KFeEVbNRZx',
160
+ 'fyf4H8MXazm3oY',
161
+ 'Z116B9F2p',
162
+ 'GdxNJOnvdz',
163
+ 'kqVNNHfP',
164
+ 'IO3hhNu',
165
+ 'qDdC9Lcllce',
166
+ 'Et7lLOg',
167
+ '6ZlQrvfgZu',
168
+ 'YXHLeZBF',
169
+ 'NH6nAd7y',
170
+ 'ARsut59gfK6j0v',
171
+ 'jPE2KXiJjnSsjn',
172
+ 'qYcG5HOJc3TtxM',
173
+ 'C2w06YGj5C',
174
+ 'kHx1pT7',
175
+ '2enXfHXw',
176
+ 'koFHBiR054aizN',
177
+ 'Uj53XTQ92Ntbq7K',
178
+ 'QjC5euFYi2AuxWb',
179
+ 'njLwvdMejA',
180
+ 'NWMzrwTAVZEb',
181
+ 's4sVqC0AyTM5h',
182
+ 'pu01jeZ6AoH',
183
+ 'SgiOfwx9qkR',
184
+ 'grjsLtBNn9eTQg',
185
+ 'XABTTaYgihZk2mq',
186
+ '2vlSCZQc3HT27F4',
187
+ 'kQZ7VQfEL3TC7P',
188
+ 'MEzqVne021W',
189
+ 'BLYPZp2SIO',
190
+ '5zDMVoqw4nH',
191
+ 't14S9uLuGKX7Lb5',
192
+ '4McODHAYTyp',
193
+ 'EAoxL5UKvMPqjH3',
194
+ 'hJpAbqp',
195
+ 'tcj63Wpz',
196
+ 'hGqEu0LxKkMv46P',
197
+ 'u2wNvb8ou19N3',
198
+ 'wUKY6Opi1kH',
199
+ ];
200
+
201
+ try {
202
+ let e = (function (e) {
203
+ if (e === undefined) {
204
+ return 'rive';
205
+ }
206
+ try {
207
+ let t;
208
+ let n;
209
+ let r = String(e);
210
+ if (isNaN(Number(e))) {
211
+ let e = r.split('').reduce((e, t) => e + t.charCodeAt(0), 0);
212
+ t = c[e % c.length] || btoa(r);
213
+ n = Math.floor((e % r.length) / 2);
214
+ } else {
215
+ let i = Number(e);
216
+ t = c[i % c.length] || btoa(r);
217
+ n = Math.floor((i % r.length) / 2);
218
+ }
219
+ let i = r.slice(0, n) + t + r.slice(n);
220
+ let o = (function (e) {
221
+ let t = String(e);
222
+ let n = t.length ^ -559038737;
223
+ for (let e = 0; e < t.length; e++) {
224
+ let r = t.charCodeAt(e);
225
+ r ^= ((e * 131 + 89) ^ (r << e % 5)) & 255;
226
+ n = (((n << 7) | (n >>> 25)) >>> 0) ^ r;
227
+ let i = (n & 65535) * 60205;
228
+ let o = ((n >>> 16) * 60205) << 16;
229
+ n = (i + o) >>> 0;
230
+ n ^= n >>> 11;
231
+ }
232
+ n ^= n >>> 15;
233
+ n = ((n & 65535) * 49842 + (((n >>> 16) * 49842) << 16)) >>> 0;
234
+ n ^= n >>> 13;
235
+ n = ((n & 65535) * 40503 + (((n >>> 16) * 40503) << 16)) >>> 0;
236
+ n ^= n >>> 16;
237
+ n = ((n & 65535) * 10196 + (((n >>> 16) * 10196) << 16)) >>> 0;
238
+ return (n ^= n >>> 15).toString(16).padStart(8, '0');
239
+ })(
240
+ (function (e) {
241
+ e = String(e);
242
+ let t = 0;
243
+ for (let n = 0; n < e.length; n++) {
244
+ let r = e.charCodeAt(n);
245
+ let i = (((t = (r + (t << 6) + (t << 16) - t) >>> 0) << n % 5) | (t >>> (32 - (n % 5)))) >>> 0;
246
+ t ^= (i ^ ((r << n % 7) | (r >>> (8 - (n % 7))))) >>> 0;
247
+ t = (t + ((t >>> 11) ^ (t << 3))) >>> 0;
248
+ }
249
+ t ^= t >>> 15;
250
+ t = ((t & 65535) * 49842 + ((((t >>> 16) * 49842) & 65535) << 16)) >>> 0;
251
+ t ^= t >>> 13;
252
+ t = ((t & 65535) * 40503 + ((((t >>> 16) * 40503) & 65535) << 16)) >>> 0;
253
+ return (t ^= t >>> 16).toString(16).padStart(8, '0');
254
+ })(i)
255
+ );
256
+ return btoa(o);
257
+ } catch (e) {
258
+ return 'topSecret';
259
+ }
260
+ })(id);
261
+ return e;
262
+ } catch (e) {
263
+ console.error('Error fetching data:', e);
264
+ }
265
+ }
266
+
267
+ export async function getVidsrcSourcesAndServers(id: string): Promise<ISource & { servers: IEpisodeServer[] }> {
268
+ const parts = id.split('$');
269
+ const [tmdbId, type, episode, season] = parts;
270
+ const baseURL = 'https://vidsrc.xyz/embed/';
271
+ const headers = {
272
+ 'User-Agent':
273
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
274
+ 'Referer': 'https://vidsrc.xyz/',
275
+ };
276
+ const servers: IEpisodeServer[] = [];
277
+ const sources: IVideo[] = [];
278
+ const url =
279
+ type === 'tv'
280
+ ? `${baseURL}tv?tmdb=${tmdbId}&season=${season}&episode=${episode}`
281
+ : `${baseURL}movie?tmdb=${tmdbId}`;
282
+
283
+ try {
284
+ // Step 1: Fetch embed iframe
285
+ const { data: html1 } = await axios.get(url, { headers });
286
+ const match1 = html1.match(/src="(.*?)"/)?.[1];
287
+ if (!match1) throw new Error('No source iframe found');
288
+ const allUrlRCP: any = [];
289
+ // Construct the RCP URL
290
+ const urlRCP = match1.startsWith('http')
291
+ ? match1
292
+ : match1.startsWith('/embed')
293
+ ? baseURL.split('/embed')[0] + match1
294
+ : 'https:' + match1;
295
+
296
+ const $ = load(html1);
297
+ $('.serversList .server').each((i, el) => {
298
+ const name = $(el).text().trim();
299
+ const hash = $(el).attr('data-hash');
300
+ allUrlRCP.push({ name, url: `${urlRCP.split('rcp')[0]}rcp/${hash!}` });
301
+ });
302
+ // Step 2: Fetch all URLs from allUrlRCP and process them
303
+ await Promise.all(
304
+ allUrlRCP.map(async ({ name, url: rcpUrl }: { name: string; url: string }) => {
305
+ try {
306
+ // console.log(`Fetching RCP for ${name} from ${rcpUrl}`);
307
+ const { data: html2 } = await axios.get(rcpUrl, {
308
+ headers: { ...headers, Referer: url },
309
+ });
310
+ // console.log(`Found RCP for ${name}: ${html2}`);
311
+ const match2 = html2.match(/src.*['"](\/(?:src|pro)rcp.*?)['"]/)?.[1];
312
+ if (!match2) return;
313
+
314
+ const urlPRORCP = rcpUrl.split('rcp')[0] + match2;
315
+
316
+ // Step 3: Fetch M3U8 file URL
317
+ // console.log(`Fetching M3U8 for ${name} from ${urlPRORCP}`);
318
+ const { data: html3 } = await axios.get(urlPRORCP, {
319
+ headers: { ...headers, Referer: rcpUrl },
320
+ });
321
+ const match3 = html3.match(/file:\s*['"]([^'"]+\.m3u8)['"]/)?.[1];
322
+ // console.log(`Found M3U8 for ${name}: ${match3}`);
323
+ if (match3) {
324
+ servers.push({
325
+ name: name,
326
+ url: match3,
327
+ });
328
+ sources.push({
329
+ url: match3,
330
+ isM3U8: match3.includes('.m3u8'),
331
+ quality: 'default',
332
+ name: name,
333
+ });
334
+ }
335
+ } catch (error) {
336
+ // Silently continue on error for individual servers
337
+ return;
338
+ }
339
+ })
340
+ );
341
+ return {
342
+ servers,
343
+ sources,
344
+ headers: { Referer: urlRCP.split('rcp')[0] },
345
+ };
346
+ } catch (error) {
347
+ throw new Error(`Failed to fetch Vidsrc stream: ${(error as Error).message}`);
348
+ }
349
+ }
350
+
351
+ export async function getMultiServers(id: string): Promise<IEpisodeServer[]> {
352
+ try {
353
+ const servers: IEpisodeServer[] = [];
354
+ const [{ servers: riveServers }, { servers: vidsrcServers }] = await Promise.all([
355
+ getRiveSourcesAndServers(id),
356
+ getVidsrcSourcesAndServers(id),
357
+ ]);
358
+ servers.push(...riveServers, ...vidsrcServers);
359
+
360
+ return servers;
361
+ } catch (error) {
362
+ throw new Error(`Failed to fetch Multistream servers: ${(error as Error).message}`);
363
+ }
364
+ }
365
+
366
+ export async function getMultiSources(id: string, server: string): Promise<ISource> {
367
+ try {
368
+ const [{ servers: _, ...riveSources }, { servers: __, ...vidsrcSources }] = await Promise.all([
369
+ getRiveSourcesAndServers(id),
370
+ getVidsrcSourcesAndServers(id),
371
+ ]);
372
+
373
+ const allSources = {
374
+ ...riveSources,
375
+ ...vidsrcSources,
376
+ sources: [...(riveSources.sources || []), ...(vidsrcSources.sources || [])],
377
+ subtitles: [...(riveSources.subtitles || []), ...(vidsrcSources.subtitles || [])],
378
+ };
379
+
380
+ const matchedSources = allSources.sources?.filter((source: IVideo) => source.name === server) || [];
381
+
382
+ if (matchedSources.length === 0) {
383
+ throw new Error(`No sources found for server: ${server}`);
384
+ }
385
+
386
+ return {
387
+ sources: matchedSources,
388
+ subtitles: allSources.subtitles || [],
389
+ };
390
+ } catch (error) {
391
+ throw new Error(`Failed to fetch MultiSources: ${(error as Error).message}`);
392
+ }
393
+ }
@@ -11,8 +11,8 @@ import {
11
11
  import { makeGetRequestWithWebView } from '../../NativeConsumet';
12
12
  class NetflixMirror extends MovieParser {
13
13
  override readonly name = 'NetflixMirror';
14
- protected override baseUrl = 'https://netfree2.cc';
15
- protected override logo = 'https://netfree2.cc//mobile/img/nf2/icon_x192.png';
14
+ protected override baseUrl = 'https://a.netfree2.cc';
15
+ protected override logo = 'https://a.netfree2.cc//mobile/img/nf2/icon_x192.png';
16
16
  protected override classPath = 'MOVIES.NetflixMirror';
17
17
  override supportedTypes = new Set([TvType.MOVIE, TvType.TVSERIES]);
18
18
  private nfCookie: null | string = 'hd=on;';
@@ -305,35 +305,70 @@ export function stringSearch(string: string, pattern: string): number {
305
305
  return count;
306
306
  }
307
307
 
308
- export function parseUrl(url: string): {
309
- href: string;
310
- origin: string;
311
- pathname: string;
312
- hostname: string;
313
- search: string;
314
- hash: string;
315
- } {
316
- // Simple URL parser for React Native
317
- try {
318
- const match = url.match(/^(https?:\/\/[^\/]+)(\/[^?#]*)?(\?[^#]*)?(#.*)?$/);
319
- if (!match) throw new Error(`Invalid URL: ${url}`);
320
-
321
- const origin = match[1] || '';
322
- const pathname = match[2] || '/';
323
- const search = match[3] || '';
324
- const hash = match[4] || '';
325
-
326
- return {
327
- href: url,
328
- origin,
329
- pathname,
330
- hostname: origin.replace(/^https?:\/\//, ''),
331
- search,
332
- hash,
333
- };
334
- } catch (e) {
335
- console.error(`Error parsing URL: ${url}`, e);
336
- // Return a minimal object with href to prevent crashes
337
- return { href: url, origin: '', pathname: '', hostname: '', search: '', hash: '' };
338
- }
308
+ interface FilterOptions {
309
+ timeout?: number;
310
+ headers?: Record<string, string>;
311
+ indicators?: string[];
312
+ concurrency?: number;
339
313
  }
314
+
315
+ export const filterValidM3U8 = async (m3u8Links: string[], options: FilterOptions = {}): Promise<string[]> => {
316
+ const {
317
+ timeout = 10000,
318
+ headers = {},
319
+ indicators = ['#EXT', '#EXTINF', '#EXT-X-', '#EXTM3U'],
320
+ concurrency = 10,
321
+ } = options;
322
+
323
+ const validLinks: string[] = [];
324
+ let index = 0;
325
+
326
+ const next = async (): Promise<void> => {
327
+ while (index < m3u8Links.length) {
328
+ const currentIndex = index++;
329
+ const url = m3u8Links[currentIndex]!;
330
+
331
+ const controller = new AbortController();
332
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
333
+
334
+ try {
335
+ const response = await fetch(url, {
336
+ headers: {
337
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
338
+ ...headers,
339
+ },
340
+ signal: controller.signal,
341
+ });
342
+
343
+ clearTimeout(timeoutId);
344
+
345
+ if (!response.ok) {
346
+ // console.warn(`❌ HTTP error (${response.status}) for ${url}`);
347
+ continue;
348
+ }
349
+
350
+ // Optional shortcut: skip non-M3U8 content types
351
+ const contentType = response.headers.get('content-type');
352
+ if (contentType && !contentType.includes('application/vnd.apple.mpegurl') && !contentType.includes('mpegurl')) {
353
+ // console.info(`⚠️ Skipping non-M3U8 type: ${url}`);
354
+ continue;
355
+ }
356
+
357
+ const content = await response.text();
358
+ if (indicators.some((ind) => content.includes(ind))) {
359
+ validLinks.push(url);
360
+ } else {
361
+ // console.info(`⚠️ No M3U8 indicators found in: ${url}`);
362
+ }
363
+ } catch (err: any) {
364
+ clearTimeout(timeoutId);
365
+ const reason = err.name === 'AbortError' ? 'timeout' : err.message;
366
+ // console.warn(`⚠️ Failed to validate M3U8 (${url}): ${reason}`);
367
+ }
368
+ }
369
+ };
370
+
371
+ // Run N concurrent validators
372
+ await Promise.all(Array.from({ length: concurrency }, () => next()));
373
+ return validLinks;
374
+ };