diff --git a/animepahe/animepahe.js b/animepahe/animepahe.js index 9633033..c3ed2a9 100644 --- a/animepahe/animepahe.js +++ b/animepahe/animepahe.js @@ -56,18 +56,14 @@ async function extractEpisodes(url) { const uuidMatch = url.match(/\/anime\/([^\/]+)/); if (!uuidMatch) throw new Error("Invalid URL"); const id = uuidMatch[1]; - console.log("Episode extraction starting for id:", id); const ddosInterceptor = new DdosGuardInterceptor(); let page = 1; const apiUrl1 = `https://animepahe.si/api?m=release&id=${id}&sort=episode_asc&page=${page}`; - console.log("Fetching page 1..."); const response1 = await ddosInterceptor.fetchWithBypass(apiUrl1); const dataText1 = await response1.text(); - console.log("Page 1 response length:", dataText1.length); const data1 = JSON.parse(dataText1); - console.log("Page 1 episodes:", data1.data.length, "Last page:", data1.last_page); for (const item of data1.data) { results.push({ @@ -78,21 +74,17 @@ async function extractEpisodes(url) { const lastPage = data1.last_page; if (lastPage > 1) { - console.log("Fetching additional pages from 2 to", lastPage); for (let p = 2; p <= lastPage; p++) { let pageData = null; let retries = 0; while (!pageData && retries < 3) { try { const apiUrl = `https://animepahe.si/api?m=release&id=${id}&sort=episode_asc&page=${p}`; - console.log("Fetching page", p, "attempt", retries + 1); const response = await ddosInterceptor.fetchWithBypass(apiUrl); const dataText = await response.text(); pageData = JSON.parse(dataText); - console.log("Page", p, "success, episodes:", pageData.data.length); } catch (pageErr) { retries++; - console.log("Page", p, "error:", pageErr.message); } } if (pageData) { @@ -106,10 +98,8 @@ async function extractEpisodes(url) { } } - console.log("Total episodes fetched:", results.length); return JSON.stringify(results); } catch (err) { - console.log("Episodes error:", err.message); return JSON.stringify([{ href: "Error", number: "Error" @@ -204,44 +194,25 @@ class DdosGuardInterceptor { } async fetchWithBypass(url, options = {}) { - let retries = 0; - const maxRetries = 10; + let response = await this.fetchWithCookies(url, options); + + const isBlocked = await this.isBlockedResponse(response); - while (retries < maxRetries) { - try { - let response = await this.fetchWithCookies(url, options); + if (!isBlocked) { + return response; + } - const isBlocked = await this.isBlockedResponse(response); - - if (!isBlocked) { - return response; - } - if (this.cookieStore["__ddg2_"]) { - response = await this.fetchWithCookies(url, options); - if (!await this.isBlockedResponse(response)) { - return response; - } - } + if (this.cookieStore["__ddg2_"]) { + return this.fetchWithCookies(url, options); + } - const newCookie = await this.getNewCookie(url); - if (newCookie) { - response = await this.fetchWithCookies(url, options); - if (!await this.isBlockedResponse(response)) { - return response; - } - } - - retries++; - } catch (e) { - retries++; - if (retries >= maxRetries) { - throw e; - } - } + const newCookie = await this.getNewCookie(url); + if (!newCookie) { + return response; } - throw new Error("Max retries exceeded for DDoS bypass"); + return this.fetchWithCookies(url, options); } async fetchWithCookies(url, options) {