summary extra title
This commit is contained in:
+78
-13
@@ -694,6 +694,63 @@ class ComicInfoBuilder:
|
||||
|
||||
return result
|
||||
|
||||
def _collect_all_alt_titles(self, md: dict) -> "dict[str, list[str]]":
|
||||
"""
|
||||
Returns all known title variants grouped by language/script.
|
||||
|
||||
Groups collected (skipped when empty):
|
||||
"en" – English (language = "en")
|
||||
"de" – German (language = "de")
|
||||
"ja" – Japanese native kanji (language = "ja")
|
||||
"ja-romaji" – Japanese romanized (language = "ja-Latn" / "ja-romaji")
|
||||
"ko" – Korean native (language = "ko")
|
||||
"ko-romaji" – Korean romanized (language = "ko-Latn" / "ko-romaji")
|
||||
"zh" – Chinese native (language = "zh" / "zh-hk" / "zh-tw" / …)
|
||||
"zh-romaji" – Chinese romanized (language = "zh-Latn")
|
||||
|
||||
All variants are included (not just primary), preserving API order.
|
||||
Duplicates within a group are removed.
|
||||
"""
|
||||
_GROUPS: "dict[str, tuple]" = {
|
||||
"en": ("en",),
|
||||
"de": ("de",),
|
||||
"ja": ("ja",),
|
||||
"ja-romaji": ("ja-latn", "ja-romaji"),
|
||||
"ko": ("ko",),
|
||||
"ko-romaji": ("ko-latn", "ko-romaji"),
|
||||
"zh": ("zh", "zh-hk", "zh-tw", "zh-hans", "zh-hant"),
|
||||
"zh-romaji": ("zh-latn",),
|
||||
}
|
||||
|
||||
# Pre-build a flat lang → group mapping for O(1) lookup
|
||||
lang_to_group: "dict[str, str]" = {
|
||||
lang: group
|
||||
for group, langs in _GROUPS.items()
|
||||
for lang in langs
|
||||
}
|
||||
|
||||
result: "dict[str, list[str]]" = {}
|
||||
seen: "dict[str, set[str]]" = {}
|
||||
|
||||
for entry in (md.get("titles") or md.get("alt_titles") or []):
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
lang = (entry.get("language") or entry.get("lang") or "").lower()
|
||||
group = lang_to_group.get(lang)
|
||||
if not group:
|
||||
continue
|
||||
title = (entry.get("title") or "").strip()
|
||||
if not title:
|
||||
continue
|
||||
if group not in result:
|
||||
result[group] = []
|
||||
seen[group] = set()
|
||||
if title not in seen[group]:
|
||||
result[group].append(title)
|
||||
seen[group].add(title)
|
||||
|
||||
return result
|
||||
|
||||
# ======================================================================
|
||||
# Summary / notes
|
||||
# ======================================================================
|
||||
@@ -706,10 +763,6 @@ class ComicInfoBuilder:
|
||||
1. MAL statistics — HTML link + table with padded columns
|
||||
2. Series description — Markdown converted to HTML
|
||||
3. Alternate titles — HTML table
|
||||
|
||||
IMPORTANT: no raw \\n characters anywhere in the output — Kavita
|
||||
renders every bare newline as a <br>. Sections are separated with
|
||||
an explicit <br> instead.
|
||||
"""
|
||||
# Inline style applied to label cells for readable column spacing.
|
||||
_TD = 'style="padding-right:1.5em"'
|
||||
@@ -744,16 +797,28 @@ class ComicInfoBuilder:
|
||||
if desc_raw:
|
||||
parts.append(_md_to_html(desc_raw))
|
||||
|
||||
# 3. Alternate titles table (bottom) ------------------------------
|
||||
alt = self._collect_alt_titles(md)
|
||||
if alt:
|
||||
label_map = {"en": "EN", "de": "DE", "romaji": "Romaji", "jp": "JP (Kanji)"}
|
||||
# 3. Alternate titles table (bottom) — all variants per language ------
|
||||
all_alt = self._collect_all_alt_titles(md)
|
||||
if all_alt:
|
||||
label_map = {
|
||||
"en": "EN",
|
||||
"de": "DE",
|
||||
"ja": "JA",
|
||||
"ja-romaji": "JA Romaji",
|
||||
"ko": "KO",
|
||||
"ko-romaji": "KO Romaji",
|
||||
"zh": "ZH",
|
||||
"zh-romaji": "ZH Romaji",
|
||||
}
|
||||
alt_rows: list[str] = []
|
||||
for code in ("en", "de", "romaji", "jp"):
|
||||
if code in alt:
|
||||
alt_rows.append(
|
||||
f"<tr><td {_TD}>{label_map[code]}</td><td>{alt[code]}</td></tr>"
|
||||
)
|
||||
for group in ("en", "de", "ja", "ja-romaji",
|
||||
"ko", "ko-romaji", "zh", "zh-romaji"):
|
||||
titles = all_alt.get(group)
|
||||
if not titles:
|
||||
continue
|
||||
label = label_map[group]
|
||||
cell = "<br>".join(titles)
|
||||
alt_rows.append(f"<tr><td {_TD}>{label}</td><td>{cell}</td></tr>")
|
||||
if alt_rows:
|
||||
parts.append(f"<table>{''.join(alt_rows)}</table>")
|
||||
|
||||
|
||||
@@ -197,7 +197,6 @@ class MangaDexVolumeResolver:
|
||||
if result is None and chapter_map:
|
||||
result = self.estimate_volume_for_chapter(
|
||||
chapter_map, chapter, volume_page_counts)
|
||||
print(result)
|
||||
return result
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user