From 50f2635cc7661d8b2d69ee5130e4e0a60c35b1a3 Mon Sep 17 00:00:00 2001 From: MrGus Date: Fri, 26 Dec 2025 20:34:56 +0100 Subject: [PATCH] Update anime/hianime/source.js --- anime/hianime/source.js | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/anime/hianime/source.js b/anime/hianime/source.js index ecf1a25..0b184b6 100644 --- a/anime/hianime/source.js +++ b/anime/hianime/source.js @@ -1,7 +1,7 @@ class HiAnime { constructor() { this.type = "anime-streaming"; - this.version = "1.0.6"; + this.version = "1.0.7"; this.baseUrl = "https://hianime.to"; } @@ -112,8 +112,19 @@ class HiAnime { return "sub"; } + _stripYearHints(raw) { + const s = this._safeStr(raw).trim(); + if (!s) return ""; + return s + .replace(/\((?:19|20)\d{2}\)/g, " ") + .replace(/\b(?:19|20)\d{2}\b/g, " ") + .replace(/\s+/g, " ") + .trim(); + } + _normalizeTitle(title) { - return this._safeStr(title) + const t = this._stripYearHints(title); + return this._safeStr(t) .toLowerCase() .replace(/(season|cour|part|uncensored)/g, "") .replace(/\d+(st|nd|rd|th)/g, (m) => m.replace(/st|nd|rd|th/, "")) @@ -150,7 +161,10 @@ class HiAnime { if (!n) return false; const parts = n.split(/\s+/).filter(Boolean); if (parts.length !== 1) return false; - const t = this._normalizeTitle(n); + + const base = this._stripYearHints(n); + const t = this._normalizeTitle(base); + return t.length >= 3 && t.length <= 10; } @@ -165,7 +179,7 @@ class HiAnime { } _parseStartDate(dateStr) { - const s = this._safeStr(dateStr).trim(); // "Jul 4, 2025" + const s = this._safeStr(dateStr).trim(); if (!s) return null; const monthMap = { @@ -220,7 +234,7 @@ class HiAnime { const out = []; let m; while ((m = re.exec(html)) !== null) { - const pageUrl = String(m[1] || "").trim(); // e.g. "monster-2004-12345" + const pageUrl = String(m[1] || "").trim(); if (!pageUrl || pageUrl.startsWith("search?")) continue; const chunk = String(m[2] || ""); @@ -277,11 +291,16 @@ class HiAnime { const en = this._safeStr(media.englishTitle || media.english || "").trim(); const ro = this._safeStr(media.romajiTitle || media.romaji || "").trim(); - const targetNormJP = this._normalizeTitle(ro); - const targetNormEN = this._normalizeTitle(en); - const targetNorm = targetNormEN || targetNormJP || this._normalizeTitle(q); + const enStripped = this._stripYearHints(en); + const roStripped = this._stripYearHints(ro); - const strictTargetRaw = (this._isSingleWordStrictTarget(en) ? en : (this._isSingleWordStrictTarget(ro) ? ro : "")); + const targetNormJP = this._normalizeTitle(roStripped); + const targetNormEN = this._normalizeTitle(enStripped); + const targetNorm = targetNormEN || targetNormJP || this._normalizeTitle(this._stripYearHints(q)); + + const strictTargetRaw = + (this._isSingleWordStrictTarget(enStripped) ? enStripped : + (this._isSingleWordStrictTarget(roStripped) ? roStripped : "")); const strictNorm = strictTargetRaw ? this._normalizeTitle(strictTargetRaw) : ""; let matches = this._fetchSuggestMatches(q);