mirror of
https://git.luna-app.eu/50n50/sources
synced 2026-01-12 17:38:37 +01:00
Update animepahe/animepahe.js
This commit is contained in:
parent
1e56c7c785
commit
fbbed00c89
1 changed files with 47 additions and 13 deletions
|
|
@ -56,14 +56,18 @@ async function extractEpisodes(url) {
|
||||||
const uuidMatch = url.match(/\/anime\/([^\/]+)/);
|
const uuidMatch = url.match(/\/anime\/([^\/]+)/);
|
||||||
if (!uuidMatch) throw new Error("Invalid URL");
|
if (!uuidMatch) throw new Error("Invalid URL");
|
||||||
const id = uuidMatch[1];
|
const id = uuidMatch[1];
|
||||||
|
console.log("Episode extraction starting for id:", id);
|
||||||
|
|
||||||
const ddosInterceptor = new DdosGuardInterceptor();
|
const ddosInterceptor = new DdosGuardInterceptor();
|
||||||
|
|
||||||
let page = 1;
|
let page = 1;
|
||||||
const apiUrl1 = `https://animepahe.si/api?m=release&id=${id}&sort=episode_asc&page=${page}`;
|
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 response1 = await ddosInterceptor.fetchWithBypass(apiUrl1);
|
||||||
const dataText1 = await response1.text();
|
const dataText1 = await response1.text();
|
||||||
|
console.log("Page 1 response length:", dataText1.length);
|
||||||
const data1 = JSON.parse(dataText1);
|
const data1 = JSON.parse(dataText1);
|
||||||
|
console.log("Page 1 episodes:", data1.data.length, "Last page:", data1.last_page);
|
||||||
|
|
||||||
for (const item of data1.data) {
|
for (const item of data1.data) {
|
||||||
results.push({
|
results.push({
|
||||||
|
|
@ -74,17 +78,21 @@ async function extractEpisodes(url) {
|
||||||
|
|
||||||
const lastPage = data1.last_page;
|
const lastPage = data1.last_page;
|
||||||
if (lastPage > 1) {
|
if (lastPage > 1) {
|
||||||
|
console.log("Fetching additional pages from 2 to", lastPage);
|
||||||
for (let p = 2; p <= lastPage; p++) {
|
for (let p = 2; p <= lastPage; p++) {
|
||||||
let pageData = null;
|
let pageData = null;
|
||||||
let retries = 0;
|
let retries = 0;
|
||||||
while (!pageData && retries < 3) {
|
while (!pageData && retries < 3) {
|
||||||
try {
|
try {
|
||||||
const apiUrl = `https://animepahe.si/api?m=release&id=${id}&sort=episode_asc&page=${p}`;
|
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 response = await ddosInterceptor.fetchWithBypass(apiUrl);
|
||||||
const dataText = await response.text();
|
const dataText = await response.text();
|
||||||
pageData = JSON.parse(dataText);
|
pageData = JSON.parse(dataText);
|
||||||
|
console.log("Page", p, "success, episodes:", pageData.data.length);
|
||||||
} catch (pageErr) {
|
} catch (pageErr) {
|
||||||
retries++;
|
retries++;
|
||||||
|
console.log("Page", p, "error:", pageErr.message);
|
||||||
if (retries < 3) {
|
if (retries < 3) {
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
}
|
}
|
||||||
|
|
@ -101,8 +109,10 @@ async function extractEpisodes(url) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Total episodes fetched:", results.length);
|
||||||
return JSON.stringify(results);
|
return JSON.stringify(results);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log("Episodes error:", err.message);
|
||||||
return JSON.stringify([{
|
return JSON.stringify([{
|
||||||
href: "Error",
|
href: "Error",
|
||||||
number: "Error"
|
number: "Error"
|
||||||
|
|
@ -197,25 +207,49 @@ class DdosGuardInterceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchWithBypass(url, options = {}) {
|
async fetchWithBypass(url, options = {}) {
|
||||||
let response = await this.fetchWithCookies(url, options);
|
let retries = 0;
|
||||||
|
const maxRetries = 10;
|
||||||
|
|
||||||
const isBlocked = await this.isBlockedResponse(response);
|
while (retries < maxRetries) {
|
||||||
|
try {
|
||||||
|
let response = await this.fetchWithCookies(url, options);
|
||||||
|
|
||||||
if (!isBlocked) {
|
const isBlocked = await this.isBlockedResponse(response);
|
||||||
return response;
|
|
||||||
|
if (!isBlocked) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cookieStore["__ddg2_"]) {
|
||||||
|
response = await this.fetchWithCookies(url, options);
|
||||||
|
if (!await this.isBlockedResponse(response)) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const newCookie = await this.getNewCookie(url);
|
||||||
|
if (newCookie) {
|
||||||
|
response = await this.fetchWithCookies(url, options);
|
||||||
|
if (!await this.isBlockedResponse(response)) {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
retries++;
|
||||||
|
if (retries < maxRetries) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
retries++;
|
||||||
|
if (retries < maxRetries) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 500));
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error("Max retries exceeded for DDoS bypass");
|
||||||
if (this.cookieStore["__ddg2_"]) {
|
|
||||||
return this.fetchWithCookies(url, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
const newCookie = await this.getNewCookie(url);
|
|
||||||
if (!newCookie) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.fetchWithCookies(url, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchWithCookies(url, options) {
|
async fetchWithCookies(url, options) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue