From 74bd2a3c01cc84d1d0d1ad4c8320ae11c90b940b Mon Sep 17 00:00:00 2001 From: Inside4ndroid Date: Wed, 9 Apr 2025 18:48:08 +0100 Subject: [PATCH] fixed 2embed issue. --- src/extractors/2Embed.js | 70 +++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 11 deletions(-) diff --git a/src/extractors/2Embed.js b/src/extractors/2Embed.js index eec6a1c..dfda186 100644 --- a/src/extractors/2Embed.js +++ b/src/extractors/2Embed.js @@ -213,15 +213,33 @@ async function resolve(url, referer) { await parseSubs(unpackedJS); - const fileRegex = /sources\s*:\s*\[\s*\{\s*file\s*:\s*"([^"]+)"/; - const matchUri = unpackedJS.match(fileRegex); + const docheck = unpackedJS.includes("\"hls2\":\"https"); - if (matchUri && matchUri[1]) { - return matchUri[1]; + if (docheck) { + const fileRegex = /links=.*hls2\":\"(.*?)\"};/; + + const matchUri = unpackedJS.match(fileRegex); + + if (matchUri && matchUri[1]) { + return matchUri[1]; + } else { + console.error("Could not find file URL in unpacked JS"); + return null; + } } else { - console.error("Could not find file URL in unpacked JS"); - return null; + const fileRegex = /sources\s*:\s*\[\s*\{\s*file\s*:\s*"([^"]+)"/; + + const matchUri = unpackedJS.match(fileRegex); + + if (matchUri && matchUri[1]) { + return matchUri[1]; + } else { + console.error("Could not find file URL in unpacked JS"); + return null; + } } + + } else { console.error("JsUnpacker could not detect packed data in resolve response"); return null; @@ -302,22 +320,52 @@ async function parseSubs(scriptstring) { } try { - const setupMatch = scriptstring.match(/jwplayer\([\s\S]*?\)\.setup\((\{[\s\S]*?\})\)/); + // First extract the links object from the script + const linksMatch = scriptstring.match(/var links\s*=\s*({[^;]*});/); + if (!linksMatch) { + console.error("Could not find links object in script"); + return; + } + + let linksStr = linksMatch[1] + .replace(/'/g, '"') // Replace single quotes with double quotes for JSON + .replace(/([{,]\s*)([a-zA-Z0-9_$]+)(\s*:)/g, '$1"$2"$3'); // Ensure proper JSON keys + + const links = JSON.parse(linksStr); + const videoUrl = links.hls2; // Use hls2 as fallback if hls4 doesn't exist + + // Now extract the JWPlayer setup configuration + const setupMatch = scriptstring.match(/jwplayer\(["']vplayer["']\)\.setup\((\{[\s\S]*?\})\);[\s\S]*?$/); if (!setupMatch || !setupMatch[1]) { + console.error("Could not find JWPlayer setup configuration"); return; } let setupStr = setupMatch[1]; - setupStr = setupStr.replace(/\\'/g, "'"); - setupStr = setupStr.replace(/'/g, '"'); - setupStr = setupStr.replace(/([{,]\s*)([a-zA-Z0-9_$]+)(\s*:)/g, '$1"$2"$3'); - setupStr = setupStr.replace(/,\s*([}\]])/g, '$1'); + // Replace JavaScript expressions with actual values + setupStr = setupStr.replace(/links\.hls4\s*\|\|\s*links\.hls2/g, `"${videoUrl}"`); + + // Clean the string for JSON parsing + setupStr = setupStr + .replace(/\\'/g, "'") + .replace(/([{,]\s*)([a-zA-Z0-9_$]+)(\s*:)/g, '$1"$2"$3') + .replace(/'/g, '"') + .replace(/,\s*([}\]])/g, '$1') + .replace(/"true"/g, 'true') + .replace(/"false"/g, 'false') + .replace(/"null"/g, 'null'); let setupConfig; try { setupConfig = JSON.parse(setupStr); } catch (err) { + console.error("JSON parse error:", err, "in string:", setupStr); + return; + } + + if (!setupConfig.tracks) { + console.log("No tracks found in setup configuration"); return; }