+11
-23
@@ -1,6 +1,5 @@
|
|||||||
let cachedAuthKey = null;
|
let cachedAuthKey = null;
|
||||||
let cachedAuthExpires = 0;
|
let cachedAuthExpires = 0;
|
||||||
let cachedCookie = null;
|
|
||||||
|
|
||||||
async function getFingerprint() {
|
async function getFingerprint() {
|
||||||
let canvasVal = "zN12a8x9c7Vb5m4l3k2j1h";
|
let canvasVal = "zN12a8x9c7Vb5m4l3k2j1h";
|
||||||
@@ -57,9 +56,9 @@ function Ks(method, urlPath, clientAuthKey) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAuthKeyAndCookie() {
|
async function getAuthKey() {
|
||||||
if (cachedAuthKey && cachedCookie && Math.floor(Date.now() / 1000) < cachedAuthExpires) {
|
if (cachedAuthKey && Math.floor(Date.now() / 1000) < cachedAuthExpires) {
|
||||||
return { authKey: cachedAuthKey, cookie: cachedCookie };
|
return cachedAuthKey;
|
||||||
}
|
}
|
||||||
const fp = await getFingerprint();
|
const fp = await getFingerprint();
|
||||||
const sessionRes = await fetchv2(
|
const sessionRes = await fetchv2(
|
||||||
@@ -68,43 +67,32 @@ async function getAuthKeyAndCookie() {
|
|||||||
'POST',
|
'POST',
|
||||||
JSON.stringify({ fp })
|
JSON.stringify({ fp })
|
||||||
);
|
);
|
||||||
const sessionText = await sessionRes.text();
|
|
||||||
|
const sessionText = typeof sessionRes.text === 'function' ? await sessionRes.text() : sessionRes;
|
||||||
const sessionData = JSON.parse(sessionText);
|
const sessionData = JSON.parse(sessionText);
|
||||||
if (!sessionData.clientAuthKey) {
|
if (!sessionData.clientAuthKey) {
|
||||||
throw new Error("Session bootstrap failed: " + sessionText);
|
throw new Error("Session bootstrap failed: " + sessionText);
|
||||||
}
|
}
|
||||||
let setCookie = null;
|
|
||||||
if (sessionRes.headers) {
|
|
||||||
if (typeof sessionRes.headers.get === 'function') {
|
|
||||||
setCookie = sessionRes.headers.get('set-cookie');
|
|
||||||
} else {
|
|
||||||
setCookie = sessionRes.headers['set-cookie'] || sessionRes.headers['Set-Cookie'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cachedAuthKey = sessionData.clientAuthKey;
|
cachedAuthKey = sessionData.clientAuthKey;
|
||||||
cachedAuthExpires = sessionData.expiresAt - 10;
|
cachedAuthExpires = sessionData.expiresAt - 10;
|
||||||
cachedCookie = setCookie ? setCookie.split(';')[0] : null;
|
return cachedAuthKey;
|
||||||
return { authKey: cachedAuthKey, cookie: cachedCookie };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchSigned(urlPath) {
|
async function fetchSigned(urlPath) {
|
||||||
const { authKey, cookie } = await getAuthKeyAndCookie();
|
const authKey = await getAuthKey();
|
||||||
const sigHeaders = Ks('GET', urlPath, authKey);
|
const sigHeaders = Ks('GET', urlPath, authKey);
|
||||||
const headers = {
|
const headers = {
|
||||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0',
|
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:151.0) Gecko/20100101 Firefox/151.0',
|
||||||
'x-av-ts': sigHeaders['x-av-ts'],
|
'x-av-ts': sigHeaders['x-av-ts'],
|
||||||
'x-av-sig': sigHeaders['x-av-sig']
|
'x-av-sig': sigHeaders['x-av-sig']
|
||||||
};
|
};
|
||||||
if (cookie) {
|
|
||||||
headers['cookie'] = cookie;
|
|
||||||
}
|
|
||||||
return await fetchv2(`https://animeverse.to${urlPath}`, headers, 'GET');
|
return await fetchv2(`https://animeverse.to${urlPath}`, headers, 'GET');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchResults(keyword) {
|
async function searchResults(keyword) {
|
||||||
try {
|
try {
|
||||||
const response = await fetchSigned('/api/v1/catalog');
|
const response = await fetchSigned('/api/v1/catalog');
|
||||||
const text = await response.text();
|
const text = typeof response.text === 'function' ? await response.text() : response;
|
||||||
const data = JSON.parse(text);
|
const data = JSON.parse(text);
|
||||||
|
|
||||||
const kw = typeof keyword === 'string' ? keyword : '';
|
const kw = typeof keyword === 'string' ? keyword : '';
|
||||||
@@ -161,7 +149,7 @@ async function extractDetails(url) {
|
|||||||
try {
|
try {
|
||||||
const slug = url.split('/').pop();
|
const slug = url.split('/').pop();
|
||||||
const response = await fetchSigned(`/api/v1/anime/${slug}`);
|
const response = await fetchSigned(`/api/v1/anime/${slug}`);
|
||||||
const text = await response.text();
|
const text = typeof response.text === 'function' ? await response.text() : response;
|
||||||
const data = JSON.parse(text);
|
const data = JSON.parse(text);
|
||||||
|
|
||||||
return JSON.stringify([{
|
return JSON.stringify([{
|
||||||
@@ -182,7 +170,7 @@ async function extractEpisodes(url) {
|
|||||||
try {
|
try {
|
||||||
const slug = url.split('/').pop();
|
const slug = url.split('/').pop();
|
||||||
const response = await fetchSigned(`/api/v1/anime/${slug}`);
|
const response = await fetchSigned(`/api/v1/anime/${slug}`);
|
||||||
const text = await response.text();
|
const text = typeof response.text === 'function' ? await response.text() : response;
|
||||||
const data = JSON.parse(text);
|
const data = JSON.parse(text);
|
||||||
|
|
||||||
const results = (data.episodes || []).map(ep => ({
|
const results = (data.episodes || []).map(ep => ({
|
||||||
@@ -206,7 +194,7 @@ async function extractStreamUrl(url) {
|
|||||||
const slug = parts.pop();
|
const slug = parts.pop();
|
||||||
|
|
||||||
const response = await fetchSigned(`/api/v1/anime/${slug}/stream/${episodeNumber}`);
|
const response = await fetchSigned(`/api/v1/anime/${slug}/stream/${episodeNumber}`);
|
||||||
const text = await response.text();
|
const text = typeof response.text === 'function' ? await response.text() : response;
|
||||||
const data = JSON.parse(text);
|
const data = JSON.parse(text);
|
||||||
|
|
||||||
return data.stream || "https://error.org/";
|
return data.stream || "https://error.org/";
|
||||||
|
|||||||
Reference in New Issue
Block a user