mirror of
https://git.luna-app.eu/50n50/sources
synced 2026-01-12 01:18:11 +01:00
Update animepahe/animepahe.js
This commit is contained in:
parent
dc859c0dbf
commit
0c9db9005f
1 changed files with 13 additions and 42 deletions
|
|
@ -56,18 +56,14 @@ 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({
|
||||||
|
|
@ -78,21 +74,17 @@ 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 (pageData) {
|
if (pageData) {
|
||||||
|
|
@ -106,10 +98,8 @@ 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"
|
||||||
|
|
@ -204,44 +194,25 @@ class DdosGuardInterceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchWithBypass(url, options = {}) {
|
async fetchWithBypass(url, options = {}) {
|
||||||
let retries = 0;
|
let response = await this.fetchWithCookies(url, options);
|
||||||
const maxRetries = 10;
|
|
||||||
|
const isBlocked = await this.isBlockedResponse(response);
|
||||||
|
|
||||||
while (retries < maxRetries) {
|
if (!isBlocked) {
|
||||||
try {
|
return response;
|
||||||
let response = await this.fetchWithCookies(url, options);
|
}
|
||||||
|
|
||||||
const isBlocked = await this.isBlockedResponse(response);
|
|
||||||
|
|
||||||
if (!isBlocked) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.cookieStore["__ddg2_"]) {
|
if (this.cookieStore["__ddg2_"]) {
|
||||||
response = await this.fetchWithCookies(url, options);
|
return this.fetchWithCookies(url, options);
|
||||||
if (!await this.isBlockedResponse(response)) {
|
}
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const newCookie = await this.getNewCookie(url);
|
const newCookie = await this.getNewCookie(url);
|
||||||
if (newCookie) {
|
if (!newCookie) {
|
||||||
response = await this.fetchWithCookies(url, options);
|
return response;
|
||||||
if (!await this.isBlockedResponse(response)) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
retries++;
|
|
||||||
} catch (e) {
|
|
||||||
retries++;
|
|
||||||
if (retries >= maxRetries) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error("Max retries exceeded for DDoS bypass");
|
return this.fetchWithCookies(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchWithCookies(url, options) {
|
async fetchWithCookies(url, options) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue