diff --git a/animedefenders/animedefenders.js b/animedefenders/animedefenders.js index 5688bbc..067008c 100644 --- a/animedefenders/animedefenders.js +++ b/animedefenders/animedefenders.js @@ -1,20 +1,21 @@ async function searchResults(keyword) { const results = []; try { - const response = await fetchv2("https://animedefenders.me/view/?wd=" + encodeURIComponent(keyword)); - const html = await response.text(); - - const regex = /[\s\S]*?data-original="(.*?)"[\s\S]*?

(.*?)<\/a><\/h3>/g; - let match; - while ((match = regex.exec(html)) !== null) { - let title = match[3].trim(); - title = title.replace(/\s*\(Uncensored\)\s*$/i, ''); - title = title.replace(/\s*BD\s*$/i, ''); - title = title.trim(); - results.push({ - title: title, - image: match[2].trim(), - href: "https://animedefenders.me" + match[1].trim() + const response = await fetchv2("https://eng.animeapps.top/api/search2.php?keyword=" + encodeURIComponent(keyword) + "&page=1&limit=200"); + const json = await response.json(); + + if (json.status === "success" && json.data) { + json.data.forEach(item => { + let title = item.postname.trim(); + title = title.replace(/\s*\(Uncensored\)\s*$/i, ''); + title = title.replace(/\s*BD\s*$/i, ''); + title = title.trim(); + + results.push({ + title: title, + image: item.ani_cover_large, + href: "https://anibd.app/" + item.postid + "?anilist=" + item.anilist + }); }); } @@ -30,89 +31,73 @@ async function searchResults(keyword) { async function extractDetails(url) { try { - const response = await fetchv2(url); - const html = await response.text(); - - const descriptionRegex = /
\s*

(.*?)<\/p>\s*<\/div>/s; - const match = html.match(descriptionRegex); - + const html = await (await fetchv2(url)).text(); + const match = html.match(/

[\s\S]*?]*>Synopsis<\/h4>([\s\S]*?)<\/div>/); let description = "N/A"; if (match && match[1]) { description = match[1] - .replace(//gi, ' ') - .replace(/<[^>]*>/g, '') - .replace(/\s+/g, ' ') - .trim(); + .replace(/]*>/g, '').replace(/<\/p>/g, ' ').replace(//gi, ' ') + .replace(/<[^>]*>/g, '').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"') + .replace(/&/g, '&').replace(/'/g, "'").replace(/ /g, ' ') + .replace(/\(Source:.*?\)\s*/gi, '').replace(/\s+/g, ' ').trim(); } - - return JSON.stringify([{ - description: description, - aliases: "N/A", - airdate: "N/A" - }]); + return JSON.stringify([{ description, aliases: "N/A", airdate: "N/A" }]); } catch (err) { - return JSON.stringify([{ - description: "Error", - aliases: "Error", - airdate: "Error" - }]); + return JSON.stringify([{ description: "Error", aliases: "Error", airdate: "Error" }]); } } async function extractEpisodes(url) { - const results = []; try { - const response = await fetchv2(url); - const html = await response.text(); + const postid = url.match(/(\d+)/)?.[1]; + if (!postid) return JSON.stringify([]); - const regex = /(\d+)<\/a>/g; - let match; + let anilist = url.match(/anilist=([\d]+)/)?.[1]; + if (!anilist) { + const html = await (await fetchv2(url)).text(); + anilist = html.match(/const\s+EP_ID\s*=\s*["'](\d+)["']/)?.[1]; + } + if (!anilist) return JSON.stringify([]); - while ((match = regex.exec(html)) !== null) { - results.push({ - href: "https://animedefenders.me" + match[1].trim(), - number: parseInt(match[2], 10) + const json = await (await fetchv2("https://epeng.animeapps.top/api2.php?epid=" + anilist)).json(); + const results = []; + if (Array.isArray(json)) { + json.forEach(server => { + server.server_data?.forEach(ep => { + results.push({ + number: parseInt(ep.name, 10), + href: "https://anibd.app/playid/" + postid + "/?server=" + server.id + "&slug=" + ep.slug + }); + }); }); } - - return JSON.stringify(results.reverse()); + return JSON.stringify(results); } catch (err) { - return JSON.stringify([{ - href: "Error", - number: "Error" - }]); + return JSON.stringify([]); } } async function extractStreamUrl(url) { try { - const response = await fetchv2(url); - const html = await response.text(); - - const subUrlRegex = /"actual_url":"([^"]+)"/; - const match = html.match(subUrlRegex); - - if (match && match[1]) { - const subUrl = match[1].replace(/\\\//g, '/'); - - const headers = { - "Referer": "https://ee.anih1.top", - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" - }; - - const subResponse = await fetchv2(subUrl, headers); - const subHtml = await subResponse.text(); - - const artplayerRegex = /url:\s*'([^']+\.m3u8)'/; - const artMatch = subHtml.match(artplayerRegex); - - if (artMatch && artMatch[1]) { - return artMatch[1]; - } + const pageHtml = await (await fetchv2(url)).text(); + const iframeUrl = pageHtml.match(/id="video-player-iframe"\s+src="([^"]+)"/)?.[1]?.replace(/&/g, '&'); + if (!iframeUrl) return JSON.stringify({ streams: [], subtitle: "" }); + + const iframeHtml = await (await fetchv2(iframeUrl, { "Referer": "https://anibd.app/" })).text(); + const streamUrl = iframeHtml.match(/url:\s*['"]([^'"]+\.m3u8)['"]/)?.[1]; + + if (streamUrl) { + return JSON.stringify({ + streams: [{ + title: "Server 1", + streamUrl: "https://playeng.animeapps.top/r2/" + streamUrl, + headers: { "Referer": "https://anibd.app/" } + }], + subtitle: "" + }); } - console.log("No stream URL found"); - return "https://error.org/"; + return JSON.stringify({ streams: [], subtitle: "" }); } catch (err) { - return "https://error.org/"; + return JSON.stringify({ streams: [], subtitle: "" }); } }