Spaces:
Build error
Build error
Delete scraper_controller.js
Browse files- scraper_controller.js +0 -71
scraper_controller.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
| 1 |
-
const VideoScraper = require('../services/scraper_service');
|
| 2 |
-
|
| 3 |
-
const INVALID_STRINGS = new Set(['null', 'undefined', 'none', 'nan', '']);
|
| 4 |
-
|
| 5 |
-
const firstValue = (...values) => {
|
| 6 |
-
return values.find((item) => {
|
| 7 |
-
if (item === undefined || item === null) return false;
|
| 8 |
-
const s = String(item).toLowerCase().trim();
|
| 9 |
-
return s !== '' && !INVALID_STRINGS.has(s);
|
| 10 |
-
});
|
| 11 |
-
};
|
| 12 |
-
|
| 13 |
-
const isDirectStreamUrl = (url) => {
|
| 14 |
-
const lower = String(url || '').toLowerCase();
|
| 15 |
-
return lower.includes('.m3u8') ||
|
| 16 |
-
lower.includes('.mp4') ||
|
| 17 |
-
lower.includes('googlevideo.com/videoplayback');
|
| 18 |
-
};
|
| 19 |
-
|
| 20 |
-
const extractLink = async (req, res) => {
|
| 21 |
-
const tmdbId = firstValue(req.query.tmdbId, req.query.id, req.body?.tmdbId);
|
| 22 |
-
const url = firstValue(req.query.url, req.body?.url);
|
| 23 |
-
const type = (firstValue(req.query.type, req.body?.type) || 'movie').toLowerCase();
|
| 24 |
-
const season = parseInt(firstValue(req.query.season, req.body?.season)) || 1;
|
| 25 |
-
const episode = parseInt(firstValue(req.query.episode, req.body?.episode)) || 1;
|
| 26 |
-
|
| 27 |
-
console.log(`[extract] Iniciando para ID: ${tmdbId || 'direct-url'}`);
|
| 28 |
-
|
| 29 |
-
if (!tmdbId && !url) {
|
| 30 |
-
return res.status(400).json({ success: false, candidates: [], error: 'No ID or URL' });
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
try {
|
| 34 |
-
const result = await VideoScraper.extractStreamUrl({ url, tmdbId, type, season, episode });
|
| 35 |
-
|
| 36 |
-
const resultCandidates = Array.isArray(result.candidates)
|
| 37 |
-
? result.candidates
|
| 38 |
-
: Array.isArray(result.results)
|
| 39 |
-
? result.results.map(r => r.url).filter(Boolean)
|
| 40 |
-
: [];
|
| 41 |
-
|
| 42 |
-
const candidateStrings = [...new Set(resultCandidates)].filter(isDirectStreamUrl);
|
| 43 |
-
const candidateObjects = candidateStrings.map((candidateUrl, index) => ({
|
| 44 |
-
url: candidateUrl,
|
| 45 |
-
name: `Server Mirror ${index + 1}`,
|
| 46 |
-
quality: 'Auto'
|
| 47 |
-
}));
|
| 48 |
-
|
| 49 |
-
const finalResponse = {
|
| 50 |
-
success: true,
|
| 51 |
-
candidates: candidateStrings, // Formato string []
|
| 52 |
-
sources: candidateObjects, // Formato objeto {}
|
| 53 |
-
urls: candidateStrings, // Backup común
|
| 54 |
-
tmdbId: result.tmdbId || tmdbId || null,
|
| 55 |
-
tmdb_id: tmdbId ? parseInt(tmdbId) : null, // Lo enviamos como string y como int por si acaso
|
| 56 |
-
type: type,
|
| 57 |
-
searchMode: Boolean(result.searchMode),
|
| 58 |
-
clientSideCheck: Boolean(result.clientSideCheck),
|
| 59 |
-
debug_info: result.debug_info || null
|
| 60 |
-
};
|
| 61 |
-
|
| 62 |
-
console.log('[extract] SUCCESS: Enviando respuesta universal');
|
| 63 |
-
return res.status(200).json(finalResponse);
|
| 64 |
-
|
| 65 |
-
} catch (error) {
|
| 66 |
-
console.error('[extract] ERROR:', error.message);
|
| 67 |
-
return res.status(500).json({ success: false, candidates: [], error: error.message });
|
| 68 |
-
}
|
| 69 |
-
};
|
| 70 |
-
|
| 71 |
-
module.exports = { extractLink };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|