Update animekai/animekai.js

This commit is contained in:
aka paul
2026-03-25 16:45:27 +00:00
parent 35986ceb2b
commit 14f0aea33d
+44 -21
View File
@@ -13,7 +13,7 @@ async function searchResults(query) {
try { try {
const encodedQuery = encodeQuery(query); const encodedQuery = encodeQuery(query);
const searchUrl = searchBaseUrl + encodedQuery; const searchUrl = searchBaseUrl + encodedQuery;
const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(searchUrl)); const response = await fetchv2(searchUrl);
const htmlText = await response.text(); const htmlText = await response.text();
const results = []; const results = [];
@@ -30,7 +30,9 @@ async function searchResults(query) {
null; null;
const imageMatch = imageMatches[index].match(extractImageRegex); const imageMatch = imageMatches[index].match(extractImageRegex);
const imageSrc = imageMatch ? imageMatch[1] : null; const imageSrc = imageMatch
? (imageMatch[1].startsWith("http") ? imageMatch[1] : baseUrl + imageMatch[1])
: null;
const titleMatch = titleMatches[index].match(extractTitleRegex); const titleMatch = titleMatches[index].match(extractTitleRegex);
const cleanTitle = titleMatch ? const cleanTitle = titleMatch ?
@@ -40,7 +42,7 @@ async function searchResults(query) {
if (fullHref && imageSrc && cleanTitle) { if (fullHref && imageSrc && cleanTitle) {
results.push({ results.push({
href: fullHref, href: fullHref,
image: "https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(imageSrc), image: imageSrc,
title: cleanTitle title: cleanTitle
}); });
} }
@@ -58,9 +60,8 @@ async function searchResults(query) {
async function extractDetails(url) { async function extractDetails(url) {
try { try {
const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); const response = await fetchv2(url);
const htmlText = await response.text(); const htmlText = await response.text();
console.log(htmlText);
const descriptionMatch = (/<div class="desc text-expand">([\s\S]*?)<\/div>/.exec(htmlText) || [])[1]; const descriptionMatch = (/<div class="desc text-expand">([\s\S]*?)<\/div>/.exec(htmlText) || [])[1];
const aliasesMatch = (/<small class="al-title text-expand">([\s\S]*?)<\/small>/.exec(htmlText) || [])[1]; const aliasesMatch = (/<small class="al-title text-expand">([\s\S]*?)<\/small>/.exec(htmlText) || [])[1];
@@ -83,7 +84,7 @@ async function extractDetails(url) {
async function extractEpisodes(url) { async function extractEpisodes(url) {
try { try {
const actualUrl = url.replace("Animekai:", "").trim(); const actualUrl = url.replace("Animekai:", "").trim();
const htmlText = await (await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(actualUrl))).text(); const htmlText = await (await fetchv2(actualUrl)).text();
const animeIdMatch = (htmlText.match(/<div class="rate-box"[^>]*data-id="([^"]+)"/) || [])[1]; const animeIdMatch = (htmlText.match(/<div class="rate-box"[^>]*data-id="([^"]+)"/) || [])[1];
if (!animeIdMatch) return JSON.stringify([{ error: "AniID not found" }]); if (!animeIdMatch) return JSON.stringify([{ error: "AniID not found" }]);
@@ -92,7 +93,7 @@ async function extractEpisodes(url) {
const token = tokenData.result; const token = tokenData.result;
const episodeListUrl = `https://anikai.to/ajax/episodes/list?ani_id=${animeIdMatch}&_=${token}`; const episodeListUrl = `https://anikai.to/ajax/episodes/list?ani_id=${animeIdMatch}&_=${token}`;
const episodeListData = await (await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(episodeListUrl))).json(); const episodeListData = await (await fetchv2(episodeListUrl)).json();
const cleanedHtml = cleanJsonHtml(episodeListData.result); const cleanedHtml = cleanJsonHtml(episodeListData.result);
const episodeRegex = /<a[^>]+num="([^"]+)"[^>]+token="([^"]+)"[^>]*>/g; const episodeRegex = /<a[^>]+num="([^"]+)"[^>]+token="([^"]+)"[^>]*>/g;
@@ -125,22 +126,48 @@ async function extractStreamUrl(url) {
actualUrl = actualUrl.replace('&_=ENCRYPT_ME', `&_=${encryptedToken}`); actualUrl = actualUrl.replace('&_=ENCRYPT_ME', `&_=${encryptedToken}`);
} }
const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(actualUrl)); const response = await fetchv2(actualUrl);
const text = await response.text(); const text = await response.text();
let ajaxResultHtml = "";
try {
const parsedAjax = JSON.parse(text);
ajaxResultHtml = parsedAjax?.result || "";
} catch {}
const cleanedHtml = cleanJsonHtml(text); const cleanedHtml = cleanJsonHtml(text);
const cleanedAjaxResultHtml = cleanJsonHtml(ajaxResultHtml);
const serverHtmlSource = cleanedAjaxResultHtml || cleanedHtml;
const subRegex = /<div class="server-items lang-group" data-id="sub"[^>]*>([\s\S]*?)<\/div>/; const subRegex = /<div class="server-items lang-group" data-id="sub"[^>]*>([\s\S]*?)<\/div>/;
const softsubRegex = /<div class="server-items lang-group" data-id="softsub"[^>]*>([\s\S]*?)<\/div>/; const softsubRegex = /<div class="server-items lang-group" data-id="softsub"[^>]*>([\s\S]*?)<\/div>/;
const dubRegex = /<div class="server-items lang-group" data-id="dub"[^>]*>([\s\S]*?)<\/div>/; const dubRegex = /<div class="server-items lang-group" data-id="dub"[^>]*>([\s\S]*?)<\/div>/;
const subMatch = subRegex.exec(cleanedHtml); const subMatch = subRegex.exec(serverHtmlSource);
const softsubMatch = softsubRegex.exec(cleanedHtml); const softsubMatch = softsubRegex.exec(serverHtmlSource);
const dubMatch = dubRegex.exec(cleanedHtml); const dubMatch = dubRegex.exec(serverHtmlSource);
const subContent = subMatch ? subMatch[1].trim() : ""; const subContent = subMatch ? subMatch[1].trim() : "";
const softsubContent = softsubMatch ? softsubMatch[1].trim() : ""; const softsubContent = softsubMatch ? softsubMatch[1].trim() : "";
const dubContent = dubMatch ? dubMatch[1].trim() : ""; const dubContent = dubMatch ? dubMatch[1].trim() : "";
const serverSpanRegex = /<span class="server"[^>]*data-lid="([^"]+)"[^>]*>Server 1<\/span>/;
const serverIdDub = serverSpanRegex.exec(dubContent)?.[1]; const extractServerId = (content) => {
const serverIdSoftsub = serverSpanRegex.exec(softsubContent)?.[1]; if (!content) {
const serverIdSub = serverSpanRegex.exec(subContent)?.[1]; return null;
}
const preferred = /<span class="server"[^>]*data-lid="([^"]+)"[^>]*>\s*Server\s*1\s*<\/span>/i.exec(content);
if (preferred?.[1]) {
return preferred[1];
}
const fallback = /<span class="server"[^>]*data-lid="([^"]+)"/i.exec(content);
return fallback?.[1] || null;
};
const serverIdDub = extractServerId(dubContent);
const serverIdSoftsub = extractServerId(softsubContent);
const serverIdSub = extractServerId(subContent);
const tokenRequestData = [ const tokenRequestData = [
{ name: "Dub", data: serverIdDub }, { name: "Dub", data: serverIdDub },
@@ -172,14 +199,13 @@ async function extractStreamUrl(url) {
const streamResponses = await Promise.all( const streamResponses = await Promise.all(
streamUrls.map(async ({ type, url }) => { streamUrls.map(async ({ type, url }) => {
try { try {
const res = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); const res = await fetchv2(url);
const json = await res.json(); const json = await res.json();
return { return {
type: type, type: type,
result: json.result result: json.result
}; };
} catch (error) { } catch (error) {
console.log(`Error fetching ${type} stream:` + error);
return { return {
type: type, type: type,
result: null result: null
@@ -212,9 +238,7 @@ async function extractStreamUrl(url) {
try { try {
const parsed = JSON.parse(result.data); const parsed = JSON.parse(result.data);
finalResults[result.name] = parsed.url; finalResults[result.name] = parsed.url;
console.log(`decrypted${result.name} URL:` + parsed.url);
} catch (error) { } catch (error) {
console.log(`Error parsing ${result.name} result:` + error);
finalResults[result.name] = null; finalResults[result.name] = null;
} }
}); });
@@ -275,11 +299,10 @@ async function extractStreamUrl(url) {
subtitles: "" subtitles: ""
}; };
console.log("RETURN: " + JSON.stringify(final));
return JSON.stringify(final); return JSON.stringify(final);
} catch (error) { } catch (error) {
console.log("Animekai fetch error:" + error); console.error("Animekai fetch error:" + error);
return "https://error.org"; return "https://error.org";
} }
} }