]*>([\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",