Update anime/hianime/source.js
This commit is contained in:
@@ -3,7 +3,7 @@ console.log("[HiAnime-TV] source.js loaded");
|
||||
function HiAnime() {
|
||||
console.log("[HiAnime-TV] constructor()");
|
||||
this.type = "anime-board";
|
||||
this.version = "1.0";
|
||||
this.version = "1.1";
|
||||
this.baseUrl = "https://hianime.to";
|
||||
}
|
||||
|
||||
@@ -19,14 +19,6 @@ HiAnime.prototype.safeString = function(str) {
|
||||
return (typeof str === "string" ? str : "");
|
||||
};
|
||||
|
||||
HiAnime.prototype.normalizeSeasonParts = function(title) {
|
||||
var s = this.safeString(title);
|
||||
return s.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "")
|
||||
.replace(/\d+(st|nd|rd|th)/g, function(m) { return m.replace(/st|nd|rd|th/, ""); })
|
||||
.replace(/season|cour|part/g, "");
|
||||
};
|
||||
|
||||
HiAnime.prototype._decodeHtml = function (s) {
|
||||
return this.safeString(s)
|
||||
.replace(/&/g, "&")
|
||||
@@ -41,10 +33,6 @@ HiAnime.prototype._decodeHtml = function(s) {
|
||||
});
|
||||
};
|
||||
|
||||
HiAnime.prototype._normalize = function(str) {
|
||||
return this.safeString(str).toLowerCase().replace(/[^a-z0-9]+/g, "");
|
||||
};
|
||||
|
||||
HiAnime.prototype._escapeRe = function (s) {
|
||||
return this.safeString(s).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
};
|
||||
@@ -53,13 +41,14 @@ HiAnime.prototype._fetch = function(url, opts) {
|
||||
var o = opts || {};
|
||||
var headers = {};
|
||||
|
||||
headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
|
||||
headers["User-Agent"] =
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
|
||||
headers["Accept"] = "text/html,application/json;q=0.9,*/*;q=0.8";
|
||||
headers["Referer"] = this.baseUrl + "/";
|
||||
|
||||
if (o.headers && typeof o.headers === "object") {
|
||||
for (var k in o.headers) {
|
||||
if (o.headers.hasOwnProperty(k)) {
|
||||
if (Object.prototype.hasOwnProperty.call(o.headers, k)) {
|
||||
headers[k] = o.headers[k];
|
||||
}
|
||||
}
|
||||
@@ -68,7 +57,15 @@ HiAnime.prototype._fetch = function(url, opts) {
|
||||
var method = o.method || "GET";
|
||||
var body = (o.body === undefined || o.body === null) ? "" : String(o.body);
|
||||
|
||||
console.log("[HiAnime-TV] fetch", method, url, "headers=", Object.keys(headers).length, "bodyLen=", body.length);
|
||||
console.log(
|
||||
"[HiAnime-TV] fetch",
|
||||
method,
|
||||
url,
|
||||
"headers=",
|
||||
Object.keys(headers).length,
|
||||
"bodyLen=",
|
||||
body.length
|
||||
);
|
||||
var r = fetch(url, { method: method, headers: headers, body: body });
|
||||
console.log("[HiAnime-TV] fetchResp status=", r.status, "ok=", r.ok);
|
||||
return r;
|
||||
@@ -81,25 +78,35 @@ HiAnime.prototype.search = function(query) {
|
||||
var q = query;
|
||||
|
||||
if (typeof q === "string") {
|
||||
try { q = JSON.parse(q); }
|
||||
catch (e) { q = { query: query, dub: false, media: { startDate: {} } }; }
|
||||
try {
|
||||
q = JSON.parse(q);
|
||||
} catch (e) {
|
||||
q = { query: query };
|
||||
}
|
||||
}
|
||||
|
||||
q = q || {};
|
||||
var queryText = this.safeString(q.query || q.title);
|
||||
var dub = !!q.dub;
|
||||
|
||||
var start = (q.media && q.media.startDate) ? q.media.startDate : {};
|
||||
var year = start.year || "";
|
||||
var month = start.month || "";
|
||||
|
||||
console.log("[HiAnime-TV] search() parsed queryText=", queryText, "dub=", dub, "year=", year, "month=", month);
|
||||
console.log(
|
||||
"[HiAnime-TV] search() parsed queryText=",
|
||||
queryText,
|
||||
"year=",
|
||||
year,
|
||||
"month=",
|
||||
month
|
||||
);
|
||||
|
||||
if (!queryText) return [];
|
||||
|
||||
var self = this;
|
||||
|
||||
var url = this.baseUrl + "/search?keyword=" + encodeURIComponent(queryText) + "&sort=default";
|
||||
var url =
|
||||
this.baseUrl +
|
||||
"/search?keyword=" +
|
||||
encodeURIComponent(queryText) +
|
||||
"&sort=default";
|
||||
if (year) url += "&sy=" + year;
|
||||
if (month) url += "&sm=" + month;
|
||||
|
||||
@@ -108,43 +115,50 @@ HiAnime.prototype.search = function(query) {
|
||||
var html = this._fetch(url).text();
|
||||
console.log("[HiAnime-TV] search() htmlLen=", (html || "").length);
|
||||
|
||||
var regex = /<a href="\/watch\/([^"]+)"[^>]+title="([^"]+)"[^>]+data-id="(\d+)"/g;
|
||||
var matches = [];
|
||||
var regex = /<a[^>]+href="\/watch\/([^"]+)"[^>]*data-id="(\d+)"[^>]*title="([^"]+)"/gi;
|
||||
|
||||
var out = [];
|
||||
var match;
|
||||
|
||||
while ((match = regex.exec(html)) !== null) {
|
||||
matches.push(match);
|
||||
}
|
||||
|
||||
console.log("[HiAnime-TV] search() matchAll count=", matches.length);
|
||||
|
||||
var out = [];
|
||||
for (var i = 0; i < matches.length; i++) {
|
||||
var m = matches[i];
|
||||
var id = m[3];
|
||||
var pageUrl = m[1];
|
||||
var title = this._decodeHtml(m[2]);
|
||||
var pagePath = match[1];
|
||||
var id = match[2];
|
||||
var title = this._decodeHtml(match[3]);
|
||||
|
||||
var image = null;
|
||||
try {
|
||||
var imageRegex = new RegExp(
|
||||
"<a href=\"/watch/" + this._escapeRe(pageUrl) + "\"[\\s\\S]*?<img[^>]+data-src=\"([^\"]+)\"",
|
||||
"<a[^>]+href=\"/watch/" +
|
||||
this._escapeRe(pagePath) +
|
||||
"\"[\\s\\S]*?<img[^>]+(?:data-src|src)=\"([^\"]+)\"",
|
||||
"i"
|
||||
);
|
||||
var imageMatch = html.match(imageRegex);
|
||||
var image = imageMatch ? imageMatch[1] : null;
|
||||
var im = html.match(imageRegex);
|
||||
image = im ? im[1] : null;
|
||||
} catch (e2) {}
|
||||
|
||||
out.push({
|
||||
id: id + "/" + (dub ? "dub" : "sub"),
|
||||
id: String(id),
|
||||
title: title,
|
||||
image: image,
|
||||
url: this.baseUrl + "/" + pageUrl,
|
||||
subOrDub: dub ? "dub" : "sub"
|
||||
url: this.baseUrl + "/watch/" + pagePath,
|
||||
subOrDub: "sub"
|
||||
});
|
||||
}
|
||||
|
||||
console.log("[HiAnime-TV] search() returning=", out.length, "first=", out[0] ? out[0].title : "none");
|
||||
console.log(
|
||||
"[HiAnime-TV] search() returning=",
|
||||
out.length,
|
||||
"first=",
|
||||
out[0] ? out[0].title : "none"
|
||||
);
|
||||
return out;
|
||||
} catch (e) {
|
||||
console.error("[HiAnime-TV] search() ERROR", String(e), e && e.stack ? e.stack : "");
|
||||
console.error(
|
||||
"[HiAnime-TV] search() ERROR",
|
||||
String(e),
|
||||
e && e.stack ? e.stack : ""
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
@@ -179,6 +193,9 @@ HiAnime.prototype.findEpisodes = function(animeId) {
|
||||
}
|
||||
}
|
||||
|
||||
id = String(id || "").trim();
|
||||
if (!id) throw new Error("Missing anime id");
|
||||
|
||||
console.log("[HiAnime-TV] findEpisodes() parsed id=", id, "subOrDub=", subOrDub);
|
||||
|
||||
var url = this.baseUrl + "/ajax/v2/episode/list/" + id;
|
||||
@@ -186,10 +203,18 @@ HiAnime.prototype.findEpisodes = function(animeId) {
|
||||
var json = res.json();
|
||||
var html = this.safeString(json.html);
|
||||
|
||||
console.log("[HiAnime-TV] findEpisodes() status=", res.status, "ok=", res.ok, "htmlLen=", html.length);
|
||||
console.log(
|
||||
"[HiAnime-TV] findEpisodes() status=",
|
||||
res.status,
|
||||
"ok=",
|
||||
res.ok,
|
||||
"htmlLen=",
|
||||
html.length
|
||||
);
|
||||
|
||||
var episodes = [];
|
||||
var regex = /<a[^>]*class="[^"]*\bep-item\b[^"]*"[^>]*data-number="(\d+)"[^>]*data-id="(\d+)"[^>]*href="([^"]+)"[\s\S]*?<div class="ep-name[^"]*"[^>]*title="([^"]+)"/g;
|
||||
var regex =
|
||||
/<a[^>]*class="[^"]*\bep-item\b[^"]*"[^>]*data-number="(\d+)"[^>]*data-id="(\d+)"[^>]*href="([^"]+)"[\s\S]*?<div class="ep-name[^"]*"[^>]*title="([^"]+)"/g;
|
||||
|
||||
var match;
|
||||
while ((match = regex.exec(html)) !== null) {
|
||||
@@ -197,14 +222,24 @@ HiAnime.prototype.findEpisodes = function(animeId) {
|
||||
id: match[2] + "/" + subOrDub,
|
||||
number: parseInt(match[1], 10),
|
||||
url: this.baseUrl + match[3],
|
||||
title: this._decodeHtml(match[4])
|
||||
title: this._decodeHtml(match[4]),
|
||||
subOrDub: subOrDub
|
||||
});
|
||||
}
|
||||
|
||||
console.log("[HiAnime-TV] findEpisodes() returning=", episodes.length, "firstEp=", episodes[0] ? episodes[0].number : "none");
|
||||
console.log(
|
||||
"[HiAnime-TV] findEpisodes() returning=",
|
||||
episodes.length,
|
||||
"firstEp=",
|
||||
episodes[0] ? episodes[0].number : "none"
|
||||
);
|
||||
return episodes;
|
||||
} catch (e) {
|
||||
console.error("[HiAnime-TV] findEpisodes() ERROR", String(e), e && e.stack ? e.stack : "");
|
||||
console.error(
|
||||
"[HiAnime-TV] findEpisodes() ERROR",
|
||||
String(e),
|
||||
e && e.stack ? e.stack : ""
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
@@ -242,22 +277,33 @@ HiAnime.prototype.findEpisodeServer = function(episode, _server) {
|
||||
}
|
||||
}
|
||||
|
||||
episodeId = String(episodeId || "").trim();
|
||||
if (!episodeId) throw new Error("Missing episode id");
|
||||
|
||||
var serverName = (_server && _server !== "default") ? String(_server) : "HD-1";
|
||||
console.log("[HiAnime-TV] parsed episodeId=", episodeId, "subOrDub=", subOrDub, "serverName=", serverName);
|
||||
console.log(
|
||||
"[HiAnime-TV] parsed episodeId=",
|
||||
episodeId,
|
||||
"subOrDub=",
|
||||
subOrDub,
|
||||
"serverName=",
|
||||
serverName
|
||||
);
|
||||
|
||||
if (serverName === "HD-1" || serverName === "HD-2" || serverName === "HD-3") {
|
||||
var serversUrl = this.baseUrl + "/ajax/v2/episode/servers?episodeId=" + episodeId;
|
||||
var serversUrl = this.baseUrl + "/ajax/v2/episode/servers?episodeId=" + encodeURIComponent(episodeId);
|
||||
console.log("[HiAnime-TV] serversUrl=", serversUrl);
|
||||
|
||||
var serverJson = this._fetch(serversUrl, { headers: { "X-Requested-With": "XMLHttpRequest" } }).json();
|
||||
var serverHtml = this.safeString(serverJson.html);
|
||||
|
||||
console.log("[HiAnime-TV] serverHtmlLen=", serverHtml.length);
|
||||
|
||||
var regex = new RegExp(
|
||||
"<div[^>]*class=\"item server-item\"[^>]*data-type=\"" + this._escapeRe(subOrDub) + "\"[^>]*data-id=\"(\\d+)\"[^>]*>\\s*<a[^>]*>\\s*" + this._escapeRe(serverName) + "\\s*</a>",
|
||||
"<div[^>]*class=\"item server-item\"[^>]*data-type=\"" +
|
||||
this._escapeRe(subOrDub) +
|
||||
"\"[^>]*data-id=\"(\\d+)\"[^>]*>[\\s\\S]*?<a[^>]*>[\\s\\S]*?" +
|
||||
this._escapeRe(serverName) +
|
||||
"[\\s\\S]*?<\\/a>",
|
||||
"i"
|
||||
);
|
||||
|
||||
@@ -267,7 +313,7 @@ HiAnime.prototype.findEpisodeServer = function(episode, _server) {
|
||||
var serverId = m[1];
|
||||
console.log("[HiAnime-TV] serverId=", serverId);
|
||||
|
||||
var sourcesUrl = this.baseUrl + "/ajax/v2/episode/sources?id=" + serverId;
|
||||
var sourcesUrl = this.baseUrl + "/ajax/v2/episode/sources?id=" + encodeURIComponent(serverId);
|
||||
console.log("[HiAnime-TV] sourcesUrl=", sourcesUrl);
|
||||
|
||||
var sourcesJson = this._fetch(sourcesUrl, { headers: { "X-Requested-With": "XMLHttpRequest" } }).json();
|
||||
@@ -279,14 +325,19 @@ HiAnime.prototype.findEpisodeServer = function(episode, _server) {
|
||||
try {
|
||||
decryptData = this.extractMegaCloud(sourcesJson.link, true);
|
||||
if (decryptData && decryptData.headersProvided) requiredHeaders = decryptData.headersProvided;
|
||||
console.log("[HiAnime-TV] extractMegaCloud ok sources=", (decryptData && decryptData.sources ? decryptData.sources.length : 0));
|
||||
console.log(
|
||||
"[HiAnime-TV] extractMegaCloud ok sources=",
|
||||
(decryptData && decryptData.sources ? decryptData.sources.length : 0)
|
||||
);
|
||||
} catch (err) {
|
||||
console.warn("[HiAnime-TV] Primary decrypter failed:", String(err));
|
||||
}
|
||||
|
||||
if (!decryptData) {
|
||||
console.warn("[HiAnime-TV] Trying fallback decrypt...");
|
||||
var fallbackUrl = "https://ac-api.ofchaos.com/api/anime/embed/convert/v2?embedUrl=" + encodeURIComponent(sourcesJson.link);
|
||||
var fallbackUrl =
|
||||
"https://ac-api.ofchaos.com/api/anime/embed/convert/v2?embedUrl=" +
|
||||
encodeURIComponent(sourcesJson.link);
|
||||
console.log("[HiAnime-TV] fallbackUrl=", fallbackUrl);
|
||||
|
||||
var fallbackRes = this._fetch(fallbackUrl);
|
||||
@@ -295,11 +346,15 @@ HiAnime.prototype.findEpisodeServer = function(episode, _server) {
|
||||
requiredHeaders = {
|
||||
"Referer": "https://megacloud.club/",
|
||||
"Origin": "https://megacloud.club",
|
||||
"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",
|
||||
"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",
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
};
|
||||
|
||||
console.log("[HiAnime-TV] fallback decrypt sources=", (decryptData && decryptData.sources ? decryptData.sources.length : 0));
|
||||
console.log(
|
||||
"[HiAnime-TV] fallback decrypt sources=",
|
||||
(decryptData && decryptData.sources ? decryptData.sources.length : 0)
|
||||
);
|
||||
}
|
||||
|
||||
var sourcesArr = (decryptData && decryptData.sources) ? decryptData.sources : [];
|
||||
@@ -339,7 +394,14 @@ HiAnime.prototype.findEpisodeServer = function(episode, _server) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log("[HiAnime-TV] FINAL stream file=", streamSource.file, "type=", streamSource.type, "subs=", subtitles.length);
|
||||
console.log(
|
||||
"[HiAnime-TV] FINAL stream file=",
|
||||
streamSource.file,
|
||||
"type=",
|
||||
streamSource.type,
|
||||
"subs=",
|
||||
subtitles.length
|
||||
);
|
||||
|
||||
return {
|
||||
server: serverName,
|
||||
@@ -361,7 +423,11 @@ HiAnime.prototype.findEpisodeServer = function(episode, _server) {
|
||||
console.warn("[HiAnime-TV] Unsupported server=", serverName);
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.error("[HiAnime-TV] findEpisodeServer() ERROR", String(e), e && e.stack ? e.stack : "");
|
||||
console.error(
|
||||
"[HiAnime-TV] findEpisodeServer() ERROR",
|
||||
String(e),
|
||||
e && e.stack ? e.stack : ""
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
@@ -377,13 +443,21 @@ HiAnime.prototype.extractMegaCloud = function(embedUrl, returnHeaders) {
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"Referer": baseDomain,
|
||||
"Origin": url.protocol + "//" + url.host,
|
||||
"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"
|
||||
"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"
|
||||
};
|
||||
|
||||
var r = this._fetch(embedUrl, { headers: headers });
|
||||
var html = r.text();
|
||||
|
||||
console.log("[HiAnime-TV] extractMegaCloud() embed status=", r.status, "ok=", r.ok, "htmlLen=", (html || "").length);
|
||||
console.log(
|
||||
"[HiAnime-TV] extractMegaCloud() embed status=",
|
||||
r.status,
|
||||
"ok=",
|
||||
r.ok,
|
||||
"htmlLen=",
|
||||
(html || "").length
|
||||
);
|
||||
|
||||
var fileIdMatch = html.match(/<title>\s*File\s+#([a-zA-Z0-9]+)\s*-/i);
|
||||
if (!fileIdMatch) throw new Error("file_id not found in embed page");
|
||||
@@ -406,15 +480,21 @@ HiAnime.prototype.extractMegaCloud = function(embedUrl, returnHeaders) {
|
||||
}
|
||||
if (!nonce) throw new Error("nonce not found");
|
||||
|
||||
var sourcesUrl = baseDomain + "embed-2/v3/e-1/getSources?id=" + fileId + "&_k=" + nonce;
|
||||
var sourcesUrl = baseDomain + "embed-2/v3/e-1/getSources?id=" + encodeURIComponent(fileId) + "&_k=" + encodeURIComponent(nonce);
|
||||
console.log("[HiAnime-TV] extractMegaCloud() sourcesUrl=", sourcesUrl);
|
||||
|
||||
var sr = this._fetch(sourcesUrl, { headers: headers });
|
||||
var sourcesJson = sr.json();
|
||||
|
||||
console.log("[HiAnime-TV] extractMegaCloud() sources status=", sr.status, "ok=", sr.ok,
|
||||
"sources=", (sourcesJson.sources ? sourcesJson.sources.length : 0),
|
||||
"tracks=", (sourcesJson.tracks ? sourcesJson.tracks.length : 0)
|
||||
console.log(
|
||||
"[HiAnime-TV] extractMegaCloud() sources status=",
|
||||
sr.status,
|
||||
"ok=",
|
||||
sr.ok,
|
||||
"sources=",
|
||||
(sourcesJson.sources ? sourcesJson.sources.length : 0),
|
||||
"tracks=",
|
||||
(sourcesJson.tracks ? sourcesJson.tracks.length : 0)
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user