dev: normalize filter.genre_* labels in genre parsing

This commit is contained in:
2026-02-24 18:50:31 +01:00
parent 16e4b5f261
commit 76b04ddaf2
2 changed files with 68 additions and 4 deletions

View File

@@ -357,6 +357,28 @@ def _get_soup_simple(url: str) -> BeautifulSoupT:
return BeautifulSoup(body, "html.parser")
def _normalize_genre_label(raw: str) -> str:
text = unescape(re.sub(r"\s+", " ", str(raw or ""))).strip()
if not text:
return ""
key_prefix = "filter.genre_"
if text.casefold().startswith(key_prefix):
slug = text[len(key_prefix) :].strip().casefold()
slug = slug.replace("_", "-")
slug = re.sub(r"[^a-z0-9-]+", "-", slug).strip("-")
if not slug:
return ""
special = {
"doku-soap": "Doku-Soap",
"scifi": "SciFi",
"fighting-shounen": "Fighting-Shounen",
}
if slug in special:
return special[slug]
return " ".join(chunk.capitalize() for chunk in slug.split("-") if chunk)
return text
def _extract_genre_names_from_html(body: str) -> List[str]:
names: List[str] = []
seen: set[str] = set()
@@ -366,7 +388,7 @@ def _extract_genre_names_from_html(body: str) -> List[str]:
)
for match in pattern.finditer(body or ""):
text = re.sub(r"<[^>]+>", " ", match.group(1) or "")
text = unescape(re.sub(r"\s+", " ", text)).strip()
text = _normalize_genre_label(text)
if not text:
continue
key = text.casefold()
@@ -1193,7 +1215,7 @@ class AniworldPlugin(BasisPlugin):
genre_blocks = soup.select("div.genre")
for genre_block in genre_blocks:
name_node = genre_block.select_one(".seriesGenreList h3")
genre_name = (name_node.get_text(" ", strip=True) if name_node else "").strip()
genre_name = _normalize_genre_label(name_node.get_text(" ", strip=True) if name_node else "")
if not genre_name:
continue
entries: List[SeriesResult] = []