diff --git a/animekai/animekai.js b/animekai/animekai.js
index 03b4ec8..64fee87 100644
--- a/animekai/animekai.js
+++ b/animekai/animekai.js
@@ -115,6 +115,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"
+ };
+
let actualUrl = url;
try {
const tokenMatch = actualUrl.match(/token=([^&]+)/);
@@ -137,7 +142,6 @@ async function extractStreamUrl(url) {
const cleanedHtml = cleanJsonHtml(text);
const cleanedAjaxResultHtml = cleanJsonHtml(ajaxResultHtml);
-
const serverHtmlSource = cleanedAjaxResultHtml || cleanedHtml;
const subRegex = /
]*>([\s\S]*?)<\/div>/;
@@ -152,17 +156,10 @@ async function extractStreamUrl(url) {
const dubContent = dubMatch ? dubMatch[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);
@@ -183,96 +180,56 @@ 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(url);
- const json = await res.json();
- return {
- type: type,
- result: json.result
- };
- } catch (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 => {
+ const streamResponses = await Promise.all(
+ streamUrls.map(async ({ type, url }) => {
try {
- const parsed = JSON.parse(result.data);
- finalResults[result.name] = parsed.url;
- } catch (error) {
- finalResults[result.name] = null;
+ const res = await fetchv2(url);
+ const json = await res.json();
+ return { type, result: json.result };
+ } catch {
+ return { type, result: null };
}
- });
+ })
+ );
- return finalResults;
- };
+ 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 => ({ name: item.type, url: json.result?.url || null }))
+ .catch(() => ({ name: item.type, url: null }))
+ );
+ const decryptResults = await Promise.all(decryptPromises);
- const decryptedUrls = await processStreams(streamUrls);
- const decryptedSub = decryptedUrls.Sub;
- const decryptedDub = decryptedUrls.Dub;
- const decryptedRaw = decryptedUrls.Softsub;
+ const urlMap = Object.fromEntries(decryptResults.map(i => [i.name, i.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"
- };
+ const decryptedSub = urlMap.Sub;
+ const decryptedDub = urlMap.Dub;
+ const decryptedRaw = urlMap.Softsub;
async function getStream(url) {
try {
const response = await fetchv2(url.replace("/e/", "/media/"), headers);
const responseJson = await response.json();
-
const result = responseJson?.result;
- const postData = {
- "text": result,
- "agent": headers["User-Agent"]
- };
-
const finalResponse = await fetchv2(
"https://enc-dec.app/api/dec-mega",
{ "Content-Type": "application/json" },
"POST",
- JSON.stringify(postData)
+ JSON.stringify({ text: result, agent: headers["User-Agent"] })
);
const finalJson = await finalResponse.json();
@@ -282,24 +239,20 @@ async function extractStreamUrl(url) {
}
}
- const streams = [];
-
const [subStream, dubStream, rawStream] = await Promise.all([
decryptedSub ? getStream(decryptedSub) : Promise.resolve(null),
decryptedDub ? getStream(decryptedDub) : Promise.resolve(null),
decryptedRaw ? getStream(decryptedRaw) : Promise.resolve(null)
]);
-
+
+ console.log("[extractStreamUrl] Sub:", subStream, "Dub:", dubStream, "Softsub:", rawStream);
+
+ const streams = [];
if (subStream) streams.push({ title: "Hardsub English", streamUrl: subStream });
- if (dubStream) streams.push({ title: "Dubbed English", streamUrl: dubStream });
- if (rawStream) streams.push({ title: "Original audio", streamUrl: rawStream });
+ if (dubStream) streams.push({ title: "Dubbed English", streamUrl: dubStream });
+ if (rawStream) streams.push({ title: "Original audio", streamUrl: rawStream });
- const final = {
- streams,
- subtitles: ""
- };
-
- return JSON.stringify(final);
+ return JSON.stringify({ streams, subtitles: "" });
} catch (error) {
console.error("Animekai fetch error:" + error);
diff --git a/animekai/animekai.json b/animekai/animekai.json
index b2c1914..9c48201 100644
--- a/animekai/animekai.json
+++ b/animekai/animekai.json
@@ -5,7 +5,7 @@
"name": "50/50",
"icon": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ3122kQwublLkZ6rf1fEpUP79BxZOFmH9BSA&s"
},
- "version": "1.0.1",
+ "version": "1.0.2",
"language": "English",
"streamType": "HLS",
"quality": "1080p",