refactor: move sibnet parsing to another place

This commit is contained in:
Kentai Radiquum 2025-03-16 13:07:30 +05:00
parent 279db4b4cb
commit 17e0c0e770
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
2 changed files with 8 additions and 216 deletions

View file

@ -74,57 +74,12 @@ export const ReleasePlayerCustom = (props: {
};
const _fetchKodikManifest = async (url: string) => {
url = url.replace("https://", "")
const response = await fetch(
`/api/proxy/${encodeURIComponent(url)}?html=true`
`https://anix-player.wah.su/?url=${url}&player=kodik`
);
const data = await response.text();
const urlParamsRe = /var urlParams = .*;$/m;
const urlParamsMatch = urlParamsRe.exec(data);
if (urlParamsMatch.length == 0) {
alert("Failed to get urlParams");
return;
}
const urlParamsStr = urlParamsMatch[0]
.replace("var urlParams = '", "")
.replace("';", "");
const urlParams = JSON.parse(urlParamsStr);
const domain = url.split("/")[0];
const urlStr = url.replace(`${domain}/`, "");
const type = urlStr.split("/")[0];
const id = urlStr.split("/")[1];
const hash = urlStr.split("/")[2];
const responseMan = await fetch(
`/api/proxy/${encodeURIComponent(`${domain}/ftor`)}?isNotAnixart=true`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
type: type,
id: id,
hash: hash,
d: urlParams.d,
d_sign: urlParams.d_sign,
pd: urlParams.pd,
pd_sign: urlParams.pd_sign,
ref: urlParams.ref,
ref_sign: urlParams.ref_sign,
bad_user: false,
cdn_is_working: true,
info: {},
}),
}
);
const dataMan = await responseMan.json();
let manifest = `https:${dataMan.links["360"][0].src.replace("360.mp4:hls:", "")}`;
let poster = `https:${dataMan.links["360"][0].src.replace("360.mp4:hls:manifest.m3u8", "thumb001.jpg")}`;
const data = await response.json();
let manifest = `https:${data.links["360"][0].src.replace("360.mp4:hls:", "")}`;
let poster = `https:${data.links["360"][0].src.replace("360.mp4:hls:manifest.m3u8", "thumb001.jpg")}`;
return { manifest, poster };
};
@ -149,13 +104,12 @@ export const ReleasePlayerCustom = (props: {
};
const _fetchSibnetManifest = async (url: string) => {
url = url.replace("https://", "")
const response = await fetch(
`/api/proxy/${encodeURIComponent(url)}?isSibnet=true`
`https://sibnet.anix-player.wah.su/?url=${url}`
);
const data = await response.json();
let manifest = data.url;
let manifest = data.video;
let poster = data.poster;
return { manifest, poster };
};

View file

@ -16,118 +16,9 @@ export default async function middleware(
if (isApiV2) {
url.searchParams.delete("API-Version");
}
const isHTML = url.searchParams.get("html") == "true" || false;
if (isHTML) {
url.searchParams.delete("html");
}
const isNotAnixart =
url.searchParams.get("isNotAnixart") == "true" || false;
if (isNotAnixart) {
url.searchParams.delete("isNotAnixart");
}
const isSibnet = url.searchParams.get("isSibnet") == "true" || false;
if (isSibnet) {
url.searchParams.delete("isSibnet");
}
let path = url.pathname.match(/\/api\/proxy\/(.*)/)?.[1] + url.search;
let data = null;
path = decodeURIComponent(path);
console.log(path);
// if (
// (isHTML || isNotAnixart || isSibnet) &&
// !(
// path.startsWith("https://kodik.info") ||
// path.startsWith("https://aniqit.com") ||
// path.startsWith("https://video.sibnet.ru") ||
// path.includes("sibnet.ru")
// )
// ) {
// console.log("URL NOT ALLOWED");
// return new Response(JSON.stringify({ message: "URL not allowed" }), {
// status: 403,
// headers: {
// "Content-Type": "application/json",
// },
// });
// }
if (isSibnet) {
const page = await fetch(`https://${path}`, {
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
},
}).catch((err) => {
console.log(err);
return new Response(err.message, {
status: 500,
});
});
const pageData = await page.text();
const videoRe = /\/v\/.*?\.mp4/;
const video = videoRe.exec(pageData);
if (!video || video.length == 0) {
return new Response(JSON.stringify({ message: "Sibnet: Video not found" }), {
status: 500,
headers: {
"Content-Type": "application/json",
},
});
}
const posterRe = /\/upload\/cover\/.*?\.jpg/;
const posterUrl = posterRe.exec(pageData);
if (!posterUrl || posterUrl.length == 0) {
return new Response(JSON.stringify({ message: "Sibnet: Poster not found" }), {
status: 500,
headers: {
"Content-Type": "application/json",
},
});
}
const response = await fetch(`https://video.sibnet.ru${video[0]}`, {
redirect: "manual",
headers: {
referer: `https://${path}`,
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
},
}).catch((err) => {
console.log(err);
return new Response(err.message, {
status: 500,
});
});
return new Response(JSON.stringify({ url: `https:${response.headers.get("Location")}`, poster: `https://st.sibnet.ru${posterUrl[0]}` }), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
}
if (isHTML) {
const response = await fetch(`https://${path}`);
data = await response.text();
return new Response(data, {
status: 200,
headers: {
"Content-Type": "text/html",
},
});
} else if (isNotAnixart) {
data = await fetchDataViaGet(`https://${path}`);
} else {
data = await fetchDataViaGet(`${API_URL}/${path}`, isApiV2);
}
const data = await fetchDataViaGet(`${API_URL}/${path}`, isApiV2);
if (!data) {
return new Response(JSON.stringify({ message: "Error Fetching Data" }), {
@ -152,60 +43,7 @@ export default async function middleware(
if (isApiV2) {
url.searchParams.delete("API-Version");
}
const isNotAnixart =
url.searchParams.get("isNotAnixart") == "true" || false;
if (isNotAnixart) {
url.searchParams.delete("isNotAnixart");
}
let path = url.pathname.match(/\/api\/proxy\/(.*)/)?.[1] + url.search;
path = decodeURIComponent(path);
console.log(path);
if (isNotAnixart) {
// if (
// !(
// path.startsWith("https://kodik.info") ||
// path.startsWith("https://aniqit.com")
// )
// ) {
// console.log("URL NOT ALLOWED");
// return new Response(JSON.stringify({ message: "URL not allowed" }), {
// status: 403,
// headers: {
// "Content-Type": "application/json",
// },
// });
// }
const params = await request.json()
const formData = new FormData();
for (const [key, value] of Object.entries(params)) {
formData.append(key as any, value as any);
}
const response = await fetch(`https://anix-c.wah.su/https://${path}`, {
method: "POST",
body: formData,
headers: {
origin: "anix.wah.su"
}
}).catch((err) => {
console.log(err);
return new Response(err.message, {
status: 500,
});
});
const data = await response.json();
return new Response(JSON.stringify(data), {
status: 200,
headers: {
"Content-Type": "application/json",
},
});
}
const path = url.pathname.match(/\/api\/proxy\/(.*)/)?.[1] + url.search;
const ReqContentTypeHeader = request.headers.get("Content-Type") || "";
let ResContentTypeHeader = "";