crucial changes

This commit is contained in:
tapframe 2025-07-27 16:14:30 +05:30
parent 9006d312b8
commit f36a9a9780
4 changed files with 930 additions and 6 deletions

@ -1 +1 @@
Subproject commit 6be646d6702a809b28eac63b7d04a453f756c402
Subproject commit 10a18e6867d4600851c8b263a2d82665298b3990

894
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -29,7 +29,7 @@
"@types/react-native-video": "^5.0.20",
"axios": "^1.10.0",
"base64-js": "^1.5.1",
"cheerio": "^1.1.0",
"cheerio-without-node-native": "^0.20.2",
"cors": "^2.8.5",
"date-fns": "^4.1.0",
"eventemitter3": "^5.0.1",

View file

@ -25,6 +25,7 @@ export interface ScraperInfo {
export interface LocalScraperResult {
title: string;
name?: string;
url: string;
quality?: string;
size?: string;
@ -297,6 +298,18 @@ class LocalScraperService {
const moduleExports = {};
const moduleObj = { exports: moduleExports };
// Try to load cheerio-without-node-native
let cheerio = null;
try {
cheerio = require('cheerio-without-node-native');
} catch (error) {
try {
cheerio = require('react-native-cheerio');
} catch (error2) {
// Cheerio not available, scrapers will fall back to regex
}
}
const sandbox = {
console: {
log: (...args: any[]) => logger.log('[Scraper]', ...args),
@ -313,6 +326,19 @@ class LocalScraperService {
parseFloat,
encodeURIComponent,
decodeURIComponent,
// Add require function for specific modules
require: (moduleName: string) => {
switch (moduleName) {
case 'cheerio-without-node-native':
if (cheerio) return cheerio;
throw new Error('cheerio-without-node-native not available');
case 'react-native-cheerio':
if (cheerio) return cheerio;
throw new Error('react-native-cheerio not available');
default:
throw new Error(`Module '${moduleName}' is not available in sandbox`);
}
},
// Add fetch for HTTP requests (using axios as polyfill)
fetch: async (url: string, options: any = {}) => {
const axiosConfig = {
@ -359,7 +385,7 @@ class LocalScraperService {
try {
// Create function from code
const func = new Function('sandbox', 'params', `
const { console, setTimeout, clearTimeout, Promise, JSON, Date, Math, parseInt, parseFloat, encodeURIComponent, decodeURIComponent, axios, fetch, module, exports, global } = sandbox;
const { console, setTimeout, clearTimeout, Promise, JSON, Date, Math, parseInt, parseFloat, encodeURIComponent, decodeURIComponent, require, axios, fetch, module, exports, global } = sandbox;
${code}
// Call the main function (assuming it's exported)
@ -404,8 +430,9 @@ class LocalScraperService {
return results.map((result, index) => {
const stream: Stream = {
name: result.title || `${scraper.name} Stream ${index + 1}`,
title: result.title || `${scraper.name} Stream ${index + 1}`,
// Preserve scraper's name and title if provided, otherwise use fallbacks
name: result.name || result.title || `${scraper.name} Stream ${index + 1}`,
title: result.title || result.name || `${scraper.name} Stream ${index + 1}`,
url: result.url,
addon: scraper.id,
addonId: scraper.id,
@ -422,6 +449,11 @@ class LocalScraperService {
stream.infoHash = result.infoHash;
}
// Preserve any additional fields from the scraper result
if (result.quality && !stream.quality) {
stream.quality = result.quality;
}
return stream;
}).filter(stream => stream.url); // Filter out streams without URLs
}