diff --git a/animekai/animekai.js b/animekai/animekai.js index 7550ae4..03b4ec8 100644 --- a/animekai/animekai.js +++ b/animekai/animekai.js @@ -13,7 +13,7 @@ async function searchResults(query) { try { const encodedQuery = encodeQuery(query); 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 results = []; @@ -30,7 +30,9 @@ async function searchResults(query) { null; 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 cleanTitle = titleMatch ? @@ -40,7 +42,7 @@ async function searchResults(query) { if (fullHref && imageSrc && cleanTitle) { results.push({ href: fullHref, - image: "https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(imageSrc), + image: imageSrc, title: cleanTitle }); } @@ -58,9 +60,8 @@ async function searchResults(query) { async function extractDetails(url) { try { - const response = await fetchv2("https://deno-proxies-sznvnpnxwhbv.deno.dev/?url=" + encodeURIComponent(url)); + const response = await fetchv2(url); const htmlText = await response.text(); - console.log(htmlText); const descriptionMatch = (/
([\s\S]*?)<\/div>/.exec(htmlText) || [])[1]; const aliasesMatch = (/([\s\S]*?)<\/small>/.exec(htmlText) || [])[1]; @@ -83,7 +84,7 @@ async function extractDetails(url) { async function extractEpisodes(url) { try { 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(/
]*data-id="([^"]+)"/) || [])[1]; if (!animeIdMatch) return JSON.stringify([{ error: "AniID not found" }]); @@ -92,7 +93,7 @@ async function extractEpisodes(url) { const token = tokenData.result; 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 episodeRegex = /]+num="([^"]+)"[^>]+token="([^"]+)"[^>]*>/g; @@ -125,22 +126,48 @@ async function extractStreamUrl(url) { 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(); + + let ajaxResultHtml = ""; + try { + const parsedAjax = JSON.parse(text); + ajaxResultHtml = parsedAjax?.result || ""; + } catch {} + const cleanedHtml = cleanJsonHtml(text); + const cleanedAjaxResultHtml = cleanJsonHtml(ajaxResultHtml); + + const serverHtmlSource = cleanedAjaxResultHtml || cleanedHtml; + const subRegex = /
]*>([\s\S]*?)<\/div>/; const softsubRegex = /
]*>([\s\S]*?)<\/div>/; const dubRegex = /
]*>([\s\S]*?)<\/div>/; - const subMatch = subRegex.exec(cleanedHtml); - const softsubMatch = softsubRegex.exec(cleanedHtml); - const dubMatch = dubRegex.exec(cleanedHtml); + 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 serverSpanRegex = /]*data-lid="([^"]+)"[^>]*>Server 1<\/span>/; - const serverIdDub = serverSpanRegex.exec(dubContent)?.[1]; - const serverIdSoftsub = serverSpanRegex.exec(softsubContent)?.[1]; - const serverIdSub = serverSpanRegex.exec(subContent)?.[1]; + + const extractServerId = (content) => { + 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; + }; + + const serverIdDub = extractServerId(dubContent); + const serverIdSoftsub = extractServerId(softsubContent); + const serverIdSub = extractServerId(subContent); const tokenRequestData = [ { name: "Dub", data: serverIdDub }, @@ -172,14 +199,13 @@ async function extractStreamUrl(url) { 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 res = await fetchv2(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 @@ -212,9 +238,7 @@ async function extractStreamUrl(url) { try { const parsed = JSON.parse(result.data); finalResults[result.name] = parsed.url; - console.log(`decrypted${result.name} URL:` + parsed.url); } catch (error) { - console.log(`Error parsing ${result.name} result:` + error); finalResults[result.name] = null; } }); @@ -275,11 +299,10 @@ async function extractStreamUrl(url) { subtitles: "" }; - console.log("RETURN: " + JSON.stringify(final)); return JSON.stringify(final); } catch (error) { - console.log("Animekai fetch error:" + error); + console.error("Animekai fetch error:" + error); return "https://error.org"; } }