mirror of
https://github.com/JustAnimeCore/HiAnime-Api.git
synced 2026-04-17 13:51:44 +00:00
subtitles
This commit is contained in:
@@ -5,9 +5,12 @@ export const getStreamInfo = async (req, res, fallback = false) => {
|
|||||||
const input = req.query.id;
|
const input = req.query.id;
|
||||||
const server = req.query.server;
|
const server = req.query.server;
|
||||||
const type = req.query.type;
|
const type = req.query.type;
|
||||||
const match = input.match(/ep=(\d+)/);
|
const ep = req.query.ep;
|
||||||
if (!match) throw new Error("Invalid URL format");
|
|
||||||
const finalId = match[1];
|
let finalId = ep || input?.match(/ep=(\d+)/)?.[1] || input;
|
||||||
|
|
||||||
|
if (!finalId) throw new Error("Invalid URL format: episode ID missing");
|
||||||
|
|
||||||
const streamingInfo = await extractStreamingInfo(finalId, server, type, fallback);
|
const streamingInfo = await extractStreamingInfo(finalId, server, type, fallback);
|
||||||
return streamingInfo;
|
return streamingInfo;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -59,7 +59,26 @@ async function extractStreamingInfo(id, name, type, fallback) {
|
|||||||
type,
|
type,
|
||||||
fallback
|
fallback
|
||||||
);
|
);
|
||||||
return { streamingLink, servers };
|
|
||||||
|
if (!streamingLink) {
|
||||||
|
return { streamingLink: [], servers };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
streamingLink: [
|
||||||
|
{
|
||||||
|
link: streamingLink.link.file,
|
||||||
|
type: streamingLink.link.type,
|
||||||
|
server: streamingLink.server,
|
||||||
|
iframe: streamingLink.iframe,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tracks: streamingLink.tracks,
|
||||||
|
intro: streamingLink.intro,
|
||||||
|
outro: streamingLink.outro,
|
||||||
|
server: streamingLink.server,
|
||||||
|
servers,
|
||||||
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("An error occurred:", error);
|
console.error("An error occurred:", error);
|
||||||
return { streamingLink: [], servers: [] };
|
return { streamingLink: [], servers: [] };
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export async function decryptSources_v1(epID, id, name, type, fallback) {
|
|||||||
try {
|
try {
|
||||||
let decryptedSources = null;
|
let decryptedSources = null;
|
||||||
let iframeURL = null;
|
let iframeURL = null;
|
||||||
|
let ajaxLink = null;
|
||||||
|
|
||||||
if (fallback) {
|
if (fallback) {
|
||||||
const fallback_server = ["hd-1", "hd-3"].includes(name.toLowerCase())
|
const fallback_server = ["hd-1", "hd-3"].includes(name.toLowerCase())
|
||||||
@@ -90,41 +91,46 @@ export async function decryptSources_v1(epID, id, name, type, fallback) {
|
|||||||
decryptedSources = decryptedData;
|
decryptedSources = decryptedData;
|
||||||
} else {
|
} else {
|
||||||
const { data: sourcesData } = await axios.get(
|
const { data: sourcesData } = await axios.get(
|
||||||
`https://${v1_base_url}/ajax/v2/episode/sources?id=${id}`,
|
`https://${v4_base_url}/ajax/episode/sources?id=${id}`,
|
||||||
);
|
|
||||||
|
|
||||||
const ajaxLink = sourcesData?.link;
|
|
||||||
if (!ajaxLink) throw new Error("Missing link in sourcesData");
|
|
||||||
console.log(ajaxLink);
|
|
||||||
const sourceIdMatch = /\/([^/?]+)\?/.exec(ajaxLink);
|
|
||||||
const sourceId = sourceIdMatch?.[1];
|
|
||||||
if (!sourceId) throw new Error("Unable to extract sourceId from link");
|
|
||||||
const new_url = `https://megacloud.blog/embed-2/v3/e-1/${sourceId}?k=1`;
|
|
||||||
const { data: stream_data } = await axios.post(
|
|
||||||
"https://megacloud.zenime.site/get-sources",
|
|
||||||
{
|
|
||||||
embedUrl: new_url,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
decryptedSources = stream_data;
|
ajaxLink = sourcesData?.link;
|
||||||
// const baseUrlMatch = ajaxLink.match(
|
if (!ajaxLink) throw new Error("Missing link in sourcesData");
|
||||||
// /^(https?:\/\/[^\/]+(?:\/[^\/]+){3})/,
|
iframeURL = ajaxLink;
|
||||||
// );
|
|
||||||
// if (!baseUrlMatch) throw new Error("Could not extract base URL");
|
|
||||||
// const baseUrl = baseUrlMatch[1];
|
|
||||||
|
|
||||||
// iframeURL = `${baseUrl}/${sourceId}?k=1&autoPlay=0&oa=0&asi=1`;
|
const sourceIdMatch = /\/([^/?]+)\?/.exec(ajaxLink);
|
||||||
|
const sourceId = sourceIdMatch?.[1];
|
||||||
|
if (!sourceId) throw new Error("Unable to extract sourceId from link");
|
||||||
|
|
||||||
// const { data: rawSourceData } = await axios.get(
|
const baseUrlMatch = ajaxLink.match(/^(https?:\/\/[^\/]+(?:\/[^\/]+){3})/);
|
||||||
// `${baseUrl}/getSources?id=${sourceId}`,
|
if (!baseUrlMatch) throw new Error("Could not extract base URL");
|
||||||
// );
|
const baseUrl = baseUrlMatch[1];
|
||||||
// decryptedSources = rawSourceData;
|
|
||||||
|
const sourcesUrl = `${baseUrl}/getSources?id=${sourceId}`;
|
||||||
|
|
||||||
|
const { data: directData } = await axios.get(sourcesUrl, {
|
||||||
|
headers: {
|
||||||
|
Accept: "*/*",
|
||||||
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
|
Referer: `${ajaxLink}&autoPlay=1&oa=0&asi=1`,
|
||||||
|
"Accept-Language": "en-US,en;q=0.9",
|
||||||
|
"Accept-Encoding": "gzip, deflate, br",
|
||||||
|
"User-Agent":
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36",
|
||||||
|
Origin: baseUrl.match(/^https?:\/\/[^\/]+/)[0],
|
||||||
|
"Sec-Fetch-Dest": "empty",
|
||||||
|
"Sec-Fetch-Mode": "cors",
|
||||||
|
"Sec-Fetch-Site": "same-origin",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
decryptedSources = directData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -133,7 +139,9 @@ export async function decryptSources_v1(epID, id, name, type, fallback) {
|
|||||||
link: {
|
link: {
|
||||||
file: fallback
|
file: fallback
|
||||||
? (decryptedSources?.sources?.file ?? "")
|
? (decryptedSources?.sources?.file ?? "")
|
||||||
: (decryptedSources?.sources?.[0].file ?? ""),
|
: (Array.isArray(decryptedSources?.sources)
|
||||||
|
? (decryptedSources?.sources?.[0]?.file ?? "")
|
||||||
|
: (typeof decryptedSources?.sources === "object" ? (decryptedSources?.sources?.file ?? "") : "")),
|
||||||
type: "hls",
|
type: "hls",
|
||||||
},
|
},
|
||||||
tracks: decryptedSources.tracks ?? [],
|
tracks: decryptedSources.tracks ?? [],
|
||||||
@@ -145,7 +153,7 @@ export async function decryptSources_v1(epID, id, name, type, fallback) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
`Error during decryptSources_v1(${id}, epID=${epID}, server=${name}):`,
|
`Error during decryptSources_v1(${id}, epID=${epID}, server=${name}):`,
|
||||||
error.message,
|
error.response ? `${error.response.status} - ${error.response.statusText}` : error.message,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user