From cbabd0643e3436f6441984b695a747dfff1c4a6e Mon Sep 17 00:00:00 2001 From: aka paul <80717571+50n50@users.noreply.github.com> Date: Thu, 23 Apr 2026 22:07:29 +0200 Subject: [PATCH] fix --- animekai/dub/animekai.js | 149 +++++++++++++------------------- animekai/dub/animekai.json | 2 +- animekai/hardsub/animekai.js | 153 +++++++++++++-------------------- animekai/hardsub/animekai.json | 2 +- 4 files changed, 120 insertions(+), 186 deletions(-) diff --git a/animekai/dub/animekai.js b/animekai/dub/animekai.js index 3c23630..41eb8ec 100644 --- a/animekai/dub/animekai.js +++ b/animekai/dub/animekai.js @@ -114,6 +114,11 @@ async function extractEpisodes(url) { } async function extractStreamUrl(url) { + const headers = { + "Referer": "https://anikai.to/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + try { const tokenMatch = url.match(/token=([^&]+)/); if (tokenMatch && tokenMatch[1]) { @@ -124,8 +129,7 @@ async function extractStreamUrl(url) { url = url.replace('&_=ENCRYPT_ME', `&_=${encryptedToken}`); } - const fetchUrl = `${url}`; - const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(fetchUrl)); + const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); const text = await response.text(); let ajaxResultHtml = ""; @@ -141,25 +145,15 @@ async function extractStreamUrl(url) { const subRegex = /
]*>([\s\S]*?)<\/div>/; const softsubRegex = /
]*>([\s\S]*?)<\/div>/; const dubRegex = /
]*>([\s\S]*?)<\/div>/; - const subMatch = subRegex.exec(serverHtmlSource); - const softsubMatch = softsubRegex.exec(serverHtmlSource); - const dubMatch = dubRegex.exec(serverHtmlSource); - const subContent = subMatch ? subMatch[1].trim() : ""; - const softsubContent = softsubMatch ? softsubMatch[1].trim() : ""; - const dubContent = dubMatch ? dubMatch[1].trim() : ""; + const subContent = subRegex.exec(serverHtmlSource)?.[1]?.trim() || ""; + const softsubContent = softsubRegex.exec(serverHtmlSource)?.[1]?.trim() || ""; + const dubContent = dubRegex.exec(serverHtmlSource)?.[1]?.trim() || ""; const extractServerId = (content) => { - if (!content) { - return null; - } - + if (!content) return null; const preferred = /]*data-lid="([^"]+)"[^>]*>\s*Server\s*1\s*<\/span>/i.exec(content); - if (preferred?.[1]) { - return preferred[1]; - } - - const fallback = /]*data-lid="([^"]+)"/i.exec(content); - return fallback?.[1] || null; + if (preferred?.[1]) return preferred[1]; + return /]*data-lid="([^"]+)"/i.exec(content)?.[1] || null; }; const serverIdDub = extractServerId(dubContent); @@ -180,93 +174,68 @@ async function extractStreamUrl(url) { ); const tokenResults = await Promise.all(tokenPromises); - const streamUrls = tokenResults.map(result => { - const serverIdMap = { - "Dub": serverIdDub, - "Softsub": serverIdSoftsub, - "Sub": serverIdSub - }; - return { - type: result.name, - url: `https://anikai.to/ajax/links/view?id=${serverIdMap[result.name]}&_=${result.data}` - }; - }); + const serverIdMap = { + "Dub": serverIdDub, + "Softsub": serverIdSoftsub, + "Sub": serverIdSub + }; - const processStreams = async (streamUrls) => { - const streamResponses = await Promise.all( - streamUrls.map(async ({ type, url }) => { - try { - const res = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); - const json = await res.json(); - return { - type: type, - result: json.result - }; - } catch (error) { - console.log(`Error fetching ${type} stream:`, error); - return { - type: type, - result: null - }; - } - }) - ); + const streamUrls = tokenResults.map(result => ({ + type: result.name, + url: `https://anikai.to/ajax/links/view?id=${serverIdMap[result.name]}&_=${result.data}` + })); - const decryptRequestData = streamResponses - .filter(item => item.result) - .map(item => ({ - name: item.type, - data: item.result - })); - - if (decryptRequestData.length === 0) { - return {}; - } - - const decryptPromises = decryptRequestData.map(item => - fetchv2(`https://enc-dec.app/api/dec-kai?text=${encodeURIComponent(item.data)}`) - .then(res => res.json()) - .then(json => ({ name: item.name, data: JSON.stringify(json.result) })) - .catch(err => ({ name: item.name, error: err.toString() })) - ); - const decryptResults = await Promise.all(decryptPromises); - - const finalResults = {}; - decryptResults.forEach(result => { + // Step 1: fetch links/view via proxy + const streamResponses = await Promise.all( + streamUrls.map(async ({ type, url }) => { try { - const parsed = JSON.parse(result.data); - finalResults[result.name] = parsed.url; - console.log(`decrypted${result.name} URL:` + parsed.url); + const res = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); + const json = await res.json(); + return { type, result: json.result }; } catch (error) { - console.log(`Error parsing ${result.name} result:`, error); - finalResults[result.name] = null; + console.log(`Error fetching ${type} stream:`, error); + return { type, result: null }; } - }); + }) + ); - return finalResults; - }; + // Step 2: decrypt with browser UA — no encodeURIComponent + const decryptPromises = streamResponses + .filter(item => item.result) + .map(item => + fetchv2(`https://enc-dec.app/api/dec-kai?text=${item.result}`, headers) + .then(res => res.json()) + .then(json => { + console.log(`decrypted ${item.type} URL:`, json.result?.url); + return { name: item.type, url: json.result?.url || null }; + }) + .catch(err => ({ name: item.type, url: null })) + ); + const decryptResults = await Promise.all(decryptPromises); - const decryptedUrls = await processStreams(streamUrls); - const decryptedDub = decryptedUrls.Dub || decryptedUrls.Sub || decryptedUrls.Softsub; + const urlMap = Object.fromEntries(decryptResults.map(i => [i.name, i.url])); + const decryptedDub = urlMap.Dub || urlMap.Sub || urlMap.Softsub; - console.log(decryptedDub); - const headers = { - "Referer": "https://anikai.to/", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" - }; + console.log("Using URL:", decryptedDub); if (decryptedDub) { - const response = await fetchv2(decryptedDub.replace("/e/", "/media/"), headers); - const responseJson = await response.json(); + const mediaResponse = await fetchv2(decryptedDub.replace("/e/", "/media/"), headers); + const responseJson = await mediaResponse.json(); const result = responseJson?.result; const postData = { "text": result, - "agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" - } + "agent": headers["User-Agent"] + }; - const finalResponse = await fetchv2("https://enc-dec.app/api/dec-mega", { "Content-Type": "application/json" }, "POST", JSON.stringify(postData)); + const finalResponse = await fetchv2( + "https://enc-dec.app/api/dec-mega", + { "Content-Type": "application/json" }, + "POST", + JSON.stringify(postData) + ); const finalJson = await finalResponse.json(); + console.log("dec-mega result:", finalJson); const m3u8Link = finalJson?.result?.sources?.[0]?.file; return m3u8Link; @@ -274,7 +243,7 @@ async function extractStreamUrl(url) { return "error"; } catch (error) { - console.log("Fetch error:"+ error); + console.log("Fetch error:" + error); return "https://error.org"; } } diff --git a/animekai/dub/animekai.json b/animekai/dub/animekai.json index 30947ce..797c9c5 100644 --- a/animekai/dub/animekai.json +++ b/animekai/dub/animekai.json @@ -5,7 +5,7 @@ "name": "50/50", "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" }, - "version": "1.1.4", + "version": "1.1.5", "language": "English", "streamType": "HLS", "quality": "1080p", diff --git a/animekai/hardsub/animekai.js b/animekai/hardsub/animekai.js index 6d4f077..e887984 100644 --- a/animekai/hardsub/animekai.js +++ b/animekai/hardsub/animekai.js @@ -114,6 +114,11 @@ async function extractEpisodes(url) { } async function extractStreamUrl(url) { + const headers = { + "Referer": "https://anikai.to/", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" + }; + try { const tokenMatch = url.match(/token=([^&]+)/); if (tokenMatch && tokenMatch[1]) { @@ -124,8 +129,7 @@ async function extractStreamUrl(url) { url = url.replace('&_=ENCRYPT_ME', `&_=${encryptedToken}`); } - const fetchUrl = `${url}`; - const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(fetchUrl)); + const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); const text = await response.text(); let ajaxResultHtml = ""; @@ -141,25 +145,15 @@ async function extractStreamUrl(url) { const subRegex = /
]*>([\s\S]*?)<\/div>/; const softsubRegex = /
]*>([\s\S]*?)<\/div>/; const dubRegex = /
]*>([\s\S]*?)<\/div>/; - const subMatch = subRegex.exec(serverHtmlSource); - const softsubMatch = softsubRegex.exec(serverHtmlSource); - const dubMatch = dubRegex.exec(serverHtmlSource); - const subContent = subMatch ? subMatch[1].trim() : ""; - const softsubContent = softsubMatch ? softsubMatch[1].trim() : ""; - const dubContent = dubMatch ? dubMatch[1].trim() : ""; + const subContent = subRegex.exec(serverHtmlSource)?.[1]?.trim() || ""; + const softsubContent = softsubRegex.exec(serverHtmlSource)?.[1]?.trim() || ""; + const dubContent = dubRegex.exec(serverHtmlSource)?.[1]?.trim() || ""; const extractServerId = (content) => { - if (!content) { - return null; - } - + if (!content) return null; const preferred = /]*data-lid="([^"]+)"[^>]*>\s*Server\s*1\s*<\/span>/i.exec(content); - if (preferred?.[1]) { - return preferred[1]; - } - - const fallback = /]*data-lid="([^"]+)"/i.exec(content); - return fallback?.[1] || null; + if (preferred?.[1]) return preferred[1]; + return /]*data-lid="([^"]+)"/i.exec(content)?.[1] || null; }; const serverIdDub = extractServerId(dubContent); @@ -180,97 +174,68 @@ async function extractStreamUrl(url) { ); const tokenResults = await Promise.all(tokenPromises); - const streamUrls = tokenResults.map(result => { - const serverIdMap = { - "Dub": serverIdDub, - "Softsub": serverIdSoftsub, - "Sub": serverIdSub - }; - return { - type: result.name, - url: `https://anikai.to/ajax/links/view?id=${serverIdMap[result.name]}&_=${result.data}` - }; - }); + const serverIdMap = { + "Dub": serverIdDub, + "Softsub": serverIdSoftsub, + "Sub": serverIdSub + }; - const processStreams = async (streamUrls) => { - const streamResponses = await Promise.all( - streamUrls.map(async ({ type, url }) => { - try { - const res = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); - const json = await res.json(); - return { - type: type, - result: json.result - }; - } catch (error) { - console.log(`Error fetching ${type} stream:`, error); - return { - type: type, - result: null - }; - } - }) - ); + const streamUrls = tokenResults.map(result => ({ + type: result.name, + url: `https://anikai.to/ajax/links/view?id=${serverIdMap[result.name]}&_=${result.data}` + })); - const decryptRequestData = streamResponses - .filter(item => item.result) - .map(item => ({ - name: item.type, - data: item.result - })); - - if (decryptRequestData.length === 0) { - return {}; - } - - const decryptPromises = decryptRequestData.map(item => - fetchv2(`https://enc-dec.app/api/dec-kai?text=${encodeURIComponent(item.data)}`) - .then(res => res.json()) - .then(json => ({ name: item.name, data: JSON.stringify(json.result) })) - .catch(err => ({ name: item.name, error: err.toString() })) - ); - const decryptResults = await Promise.all(decryptPromises); - - const finalResults = {}; - decryptResults.forEach(result => { + // Step 1: fetch links/view via proxy + const streamResponses = await Promise.all( + streamUrls.map(async ({ type, url }) => { try { - const parsed = JSON.parse(result.data); - finalResults[result.name] = parsed.url; - console.log(`decrypted${result.name} URL:` + parsed.url); + const res = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); + const json = await res.json(); + return { type, result: json.result }; } catch (error) { - console.log(`Error parsing ${result.name} result:`, error); - finalResults[result.name] = null; + console.log(`Error fetching ${type} stream:`, error); + return { type, result: null }; } - }); + }) + ); - return finalResults; - }; + // Step 2: decrypt with browser UA — no encodeURIComponent + const decryptPromises = streamResponses + .filter(item => item.result) + .map(item => + fetchv2(`https://enc-dec.app/api/dec-kai?text=${item.result}`, headers) + .then(res => res.json()) + .then(json => { + console.log(`decrypted ${item.type} URL:`, json.result?.url); + return { name: item.type, url: json.result?.url || null }; + }) + .catch(err => ({ name: item.type, url: null })) + ); + const decryptResults = await Promise.all(decryptPromises); - const decryptedUrls = await processStreams(streamUrls); - const decryptedSub = decryptedUrls.Sub || decryptedUrls.Dub || decryptedUrls.Softsub; + const urlMap = Object.fromEntries(decryptResults.map(i => [i.name, i.url])); + const decryptedSub = urlMap.Sub || urlMap.Dub || urlMap.Softsub; - console.log(decryptedSub); - const headers = { - "Referer": "https://anikai.to/", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" - }; + console.log("Using URL:", decryptedSub); if (decryptedSub) { - const response = await fetchv2(decryptedSub.replace("/e/", "/media/"), headers); - const responseJson = await response.json(); - + const mediaResponse = await fetchv2(decryptedSub.replace("/e/", "/media/"), headers); + const responseJson = await mediaResponse.json(); const result = responseJson?.result; const postData = { "text": result, - "agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" - } + "agent": headers["User-Agent"] + }; - console.log(postData); - - const finalResponse = await fetchv2("https://enc-dec.app/api/dec-mega", { "Content-Type": "application/json" }, "POST", JSON.stringify(postData)); + const finalResponse = await fetchv2( + "https://enc-dec.app/api/dec-mega", + { "Content-Type": "application/json" }, + "POST", + JSON.stringify(postData) + ); const finalJson = await finalResponse.json(); - console.log(finalJson); + console.log("dec-mega result:", finalJson); const m3u8Link = finalJson?.result?.sources?.[0]?.file; return m3u8Link; @@ -278,7 +243,7 @@ async function extractStreamUrl(url) { return "error"; } catch (error) { - console.log("Fetch error:"+ error); + console.log("Fetch error:" + error); return "https://error.org"; } } diff --git a/animekai/hardsub/animekai.json b/animekai/hardsub/animekai.json index 82d746a..849774b 100644 --- a/animekai/hardsub/animekai.json +++ b/animekai/hardsub/animekai.json @@ -5,7 +5,7 @@ "name": "50/50", "icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s" }, - "version": "1.1.2", + "version": "1.1.3", "language": "English", "streamType": "HLS", "quality": "1080p",