Update anime/hianime/source.js
This commit is contained in:
@@ -6,24 +6,12 @@ class HiAnime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSettings() {
|
getSettings() {
|
||||||
return {
|
return { episodeServers: ["HD-1", "HD-2", "HD-3", "HD-4"], supportsDub: true };
|
||||||
episodeServers: ["HD-1", "HD-2", "HD-3", "HD-4"],
|
|
||||||
supportsDub: true,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_nativeFetch(url, method, headers, body) {
|
_nativeFetch(url, method, headers, body) {
|
||||||
const raw = Native.fetch(
|
const raw = Native.fetch(String(url), method || "GET", JSON.stringify(headers || {}), body == null ? "" : String(body));
|
||||||
String(url),
|
try { return JSON.parse(raw || "{}"); } catch (e) { return { ok: false, status: 0, headers: {}, body: "" }; }
|
||||||
method || "GET",
|
|
||||||
JSON.stringify(headers || {}),
|
|
||||||
body == null ? "" : String(body)
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
return JSON.parse(raw || "{}");
|
|
||||||
} catch (e) {
|
|
||||||
return { ok: false, status: 0, headers: {}, body: "" };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_getText(url, headers) {
|
_getText(url, headers) {
|
||||||
@@ -33,28 +21,27 @@ class HiAnime {
|
|||||||
|
|
||||||
_getJson(url, headers) {
|
_getJson(url, headers) {
|
||||||
const res = this._nativeFetch(url, "GET", headers, "");
|
const res = this._nativeFetch(url, "GET", headers, "");
|
||||||
try {
|
try { return JSON.parse(String(res.body || "{}")); } catch (e) { return {}; }
|
||||||
return JSON.parse(String(res.body || "{}"));
|
|
||||||
} catch (e) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
search(query) {
|
search(query) {
|
||||||
if (typeof query === "string") {
|
if (typeof query === "string") query = { query, media: { startDate: { year: 0, month: 0, day: 0 } } };
|
||||||
query = { query, media: { startDate: { year: 0, month: 0 } } };
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalize = (str) =>
|
const start = (query.media && query.media.startDate) || { year: 0, month: 0, day: 0 };
|
||||||
this.safeString(str).toLowerCase().replace(/[^a-z0-9]+/g, "");
|
const sy = start.year || 0;
|
||||||
|
const sm = start.month || 0;
|
||||||
|
const sd = start.day || 0;
|
||||||
|
|
||||||
const start = (query.media && query.media.startDate) || { year: 0, month: 0 };
|
const url =
|
||||||
|
`${this.baseUrl}/search?keyword=${encodeURIComponent(query.query)}` +
|
||||||
|
`&sy=${sy}&sm=${sm}` +
|
||||||
|
(sd ? `&sd=${sd}` : ``) +
|
||||||
|
`&sort=default`;
|
||||||
|
|
||||||
const fetchMatches = (url) => {
|
|
||||||
const html = this._getText(url, {});
|
const html = this._getText(url, {});
|
||||||
const regex = /<a href="\/watch\/([^"]+)"[^>]+title="([^"]+)"[^>]+data-id="(\d+)"/g;
|
const regex = /<a href="\/watch\/([^"]+)"[^>]+title="([^"]+)"[^>]+data-id="(\d+)"/g;
|
||||||
|
|
||||||
return [...html.matchAll(regex)].map((m) => {
|
const matches = [...html.matchAll(regex)].map((m) => {
|
||||||
const id = m[3];
|
const id = m[3];
|
||||||
const pageUrl = m[1];
|
const pageUrl = m[1];
|
||||||
const title = m[2];
|
const title = m[2];
|
||||||
@@ -73,22 +60,9 @@ class HiAnime {
|
|||||||
const imageMatch = html.match(imageRegex);
|
const imageMatch = html.match(imageRegex);
|
||||||
const image = imageMatch ? imageMatch[1] : null;
|
const image = imageMatch ? imageMatch[1] : null;
|
||||||
|
|
||||||
return {
|
return { id, pageUrl, title, image };
|
||||||
id,
|
|
||||||
pageUrl,
|
|
||||||
title,
|
|
||||||
image,
|
|
||||||
normTitleJP: normalize(this.normalizeSeasonParts(jname)),
|
|
||||||
normTitle: normalize(this.normalizeSeasonParts(title)),
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
const url =
|
|
||||||
`${this.baseUrl}/search?keyword=${encodeURIComponent(query.query)}` +
|
|
||||||
`&sy=${start.year || 0}&sm=${start.month || 0}&sort=default`;
|
|
||||||
|
|
||||||
const matches = fetchMatches(url);
|
|
||||||
if (!matches.length) return [];
|
if (!matches.length) return [];
|
||||||
|
|
||||||
const subOrDub = query.dub ? "dub" : "sub";
|
const subOrDub = query.dub ? "dub" : "sub";
|
||||||
@@ -106,11 +80,9 @@ class HiAnime {
|
|||||||
const id = parts[0];
|
const id = parts[0];
|
||||||
const subOrDub = parts[1] || "sub";
|
const subOrDub = parts[1] || "sub";
|
||||||
|
|
||||||
const json = this._getJson(`${this.baseUrl}/ajax/v2/episode/list/${id}`, {
|
const json = this._getJson(`${this.baseUrl}/ajax/v2/episode/list/${id}`, { "X-Requested-With": "XMLHttpRequest" });
|
||||||
"X-Requested-With": "XMLHttpRequest",
|
|
||||||
});
|
|
||||||
|
|
||||||
const html = String(json.html || "");
|
const html = String(json.html || "");
|
||||||
|
|
||||||
const episodes = [];
|
const episodes = [];
|
||||||
const regex =
|
const regex =
|
||||||
/<a[^>]*class="[^"]*\bep-item\b[^"]*"[^>]*data-number="(\d+)"[^>]*data-id="(\d+)"[^>]*href="([^"]+)"[\s\S]*?<div class="ep-name[^"]*"[^>]*title="([^"]+)"/g;
|
/<a[^>]*class="[^"]*\bep-item\b[^"]*"[^>]*data-number="(\d+)"[^>]*data-id="(\d+)"[^>]*href="([^"]+)"[\s\S]*?<div class="ep-name[^"]*"[^>]*title="([^"]+)"/g;
|
||||||
@@ -129,25 +101,17 @@ class HiAnime {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findEpisodeServer(episode, _server) {
|
findEpisodeServer(episode, _server) {
|
||||||
if (typeof episode === "string") {
|
if (typeof episode === "string") { try { episode = JSON.parse(episode); } catch (e) {} }
|
||||||
try {
|
|
||||||
episode = JSON.parse(episode);
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
const parts = String((episode && episode.id) || "").split("/");
|
const parts = String((episode && episode.id) || "").split("/");
|
||||||
const id = parts[0];
|
const id = parts[0];
|
||||||
const subOrDub = parts[1] || "sub";
|
const subOrDub = parts[1] || "sub";
|
||||||
const serverName = _server !== "default" ? _server : "HD-1";
|
const serverName = _server !== "default" ? _server : "HD-1";
|
||||||
|
|
||||||
if (_server === "HD-4") return null;
|
if (_server === "HD-4") return null;
|
||||||
|
|
||||||
const serverJson = this._getJson(
|
const serverJson = this._getJson(`${this.baseUrl}/ajax/v2/episode/servers?episodeId=${id}`, { "X-Requested-With": "XMLHttpRequest" });
|
||||||
`${this.baseUrl}/ajax/v2/episode/servers?episodeId=${id}`,
|
|
||||||
{ "X-Requested-With": "XMLHttpRequest" }
|
|
||||||
);
|
|
||||||
|
|
||||||
const serverHtml = String(serverJson.html || "");
|
const serverHtml = String(serverJson.html || "");
|
||||||
|
|
||||||
const regex = new RegExp(
|
const regex = new RegExp(
|
||||||
`<div[^>]*class="item server-item"[^>]*data-type="${subOrDub}"[^>]*data-id="(\\d+)"[^>]*>\\s*<a[^>]*>\\s*${serverName}\\s*</a>`,
|
`<div[^>]*class="item server-item"[^>]*data-type="${subOrDub}"[^>]*data-id="(\\d+)"[^>]*>\\s*<a[^>]*>\\s*${serverName}\\s*</a>`,
|
||||||
"i"
|
"i"
|
||||||
@@ -155,13 +119,9 @@ class HiAnime {
|
|||||||
|
|
||||||
const match = regex.exec(serverHtml);
|
const match = regex.exec(serverHtml);
|
||||||
if (!match) throw new Error(`Server "${serverName}" (${subOrDub}) not found`);
|
if (!match) throw new Error(`Server "${serverName}" (${subOrDub}) not found`);
|
||||||
|
|
||||||
const serverId = match[1];
|
const serverId = match[1];
|
||||||
|
|
||||||
const sourcesJson = this._getJson(
|
const sourcesJson = this._getJson(`${this.baseUrl}/ajax/v2/episode/sources?id=${serverId}`, { "X-Requested-With": "XMLHttpRequest" });
|
||||||
`${this.baseUrl}/ajax/v2/episode/sources?id=${serverId}`,
|
|
||||||
{ "X-Requested-With": "XMLHttpRequest" }
|
|
||||||
);
|
|
||||||
|
|
||||||
let decryptData = null;
|
let decryptData = null;
|
||||||
let requiredHeaders = {};
|
let requiredHeaders = {};
|
||||||
@@ -173,24 +133,19 @@ class HiAnime {
|
|||||||
|
|
||||||
if (!decryptData) {
|
if (!decryptData) {
|
||||||
decryptData = this._getJson(
|
decryptData = this._getJson(
|
||||||
`https://ac-api.ofchaos.com/api/anime/embed/convert/v2?embedUrl=${encodeURIComponent(
|
`https://ac-api.ofchaos.com/api/anime/embed/convert/v2?embedUrl=${encodeURIComponent(sourcesJson.link)}`,
|
||||||
sourcesJson.link
|
|
||||||
)}`,
|
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
requiredHeaders = {
|
requiredHeaders = {
|
||||||
Referer: "https://megacloud.club/",
|
Referer: "https://megacloud.club/",
|
||||||
Origin: "https://megacloud.club",
|
Origin: "https://megacloud.club",
|
||||||
"User-Agent":
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
|
|
||||||
"X-Requested-With": "XMLHttpRequest",
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const sources = decryptData.sources || [];
|
const sources = decryptData.sources || [];
|
||||||
const streamSource =
|
const streamSource = sources.find((s) => s.type === "hls") || sources.find((s) => s.type === "mp4");
|
||||||
sources.find((s) => s.type === "hls") || sources.find((s) => s.type === "mp4");
|
|
||||||
|
|
||||||
if (!streamSource || !streamSource.file) throw new Error("No valid stream file found");
|
if (!streamSource || !streamSource.file) throw new Error("No valid stream file found");
|
||||||
|
|
||||||
const subtitles = (decryptData.tracks || [])
|
const subtitles = (decryptData.tracks || [])
|
||||||
@@ -205,30 +160,10 @@ class HiAnime {
|
|||||||
return {
|
return {
|
||||||
server: serverName,
|
server: serverName,
|
||||||
headers: requiredHeaders,
|
headers: requiredHeaders,
|
||||||
videoSources: [
|
videoSources: [{ url: streamSource.file, type: streamSource.type === "hls" ? "m3u8" : "mp4", quality: "auto", subtitles }],
|
||||||
{
|
|
||||||
url: streamSource.file,
|
|
||||||
type: streamSource.type === "hls" ? "m3u8" : "mp4",
|
|
||||||
quality: "auto",
|
|
||||||
subtitles,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
safeString(str) {
|
|
||||||
return typeof str === "string" ? str : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
normalizeSeasonParts(title) {
|
|
||||||
const s = this.safeString(title);
|
|
||||||
return s
|
|
||||||
.toLowerCase()
|
|
||||||
.replace(/[^a-z0-9]+/g, "")
|
|
||||||
.replace(/\d+(st|nd|rd|th)/g, (m) => m.replace(/st|nd|rd|th/, ""))
|
|
||||||
.replace(/season|cour|part/g, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
extractMegaCloudSync(embedUrl) {
|
extractMegaCloudSync(embedUrl) {
|
||||||
const s = String(embedUrl);
|
const s = String(embedUrl);
|
||||||
const mm = s.match(/^(https?):\/\/([^\/]+)(\/.*)?$/i);
|
const mm = s.match(/^(https?):\/\/([^\/]+)(\/.*)?$/i);
|
||||||
@@ -243,8 +178,7 @@ class HiAnime {
|
|||||||
"X-Requested-With": "XMLHttpRequest",
|
"X-Requested-With": "XMLHttpRequest",
|
||||||
Referer: baseDomain,
|
Referer: baseDomain,
|
||||||
Origin: `${protocol}://${host}`,
|
Origin: `${protocol}://${host}`,
|
||||||
"User-Agent":
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const html = this._getText(embedUrl, headers);
|
const html = this._getText(embedUrl, headers);
|
||||||
@@ -258,16 +192,11 @@ class HiAnime {
|
|||||||
if (match48) nonce = match48[0];
|
if (match48) nonce = match48[0];
|
||||||
else {
|
else {
|
||||||
const match3x16 = [...html.matchAll(/["']([A-Za-z0-9]{16})["']/g)];
|
const match3x16 = [...html.matchAll(/["']([A-Za-z0-9]{16})["']/g)];
|
||||||
if (match3x16.length >= 3) {
|
if (match3x16.length >= 3) nonce = match3x16[0][1] + match3x16[1][1] + match3x16[2][1];
|
||||||
nonce = match3x16[0][1] + match3x16[1][1] + match3x16[2][1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!nonce) throw new Error("nonce not found");
|
if (!nonce) throw new Error("nonce not found");
|
||||||
|
|
||||||
const sourcesJson = this._getJson(
|
const sourcesJson = this._getJson(`${baseDomain}embed-2/v3/e-1/getSources?id=${fileId}&_k=${nonce}`, headers);
|
||||||
`${baseDomain}embed-2/v3/e-1/getSources?id=${fileId}&_k=${nonce}`,
|
|
||||||
headers
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sources: sourcesJson.sources || [],
|
sources: sourcesJson.sources || [],
|
||||||
|
|||||||
Reference in New Issue
Block a user