Files
siftlode/backend/app/plex/genres.py
T
peter 13d95ef70e feat(plex): episodes, taglines and genres in Hungarian from the HU overlay (E30 S1a)
The HU TV section lists every episode with its Hungarian title and summary, but the
overlay read only movies and shows, so every episode stayed English. It now overlays
the episodes too, and the HU tagline (new tagline_hu column, served on ?lang=hu).

Plex's HU agent returns a mixed genre vocabulary (Action beside Dráma), and a title
with no HU twin kept its English list, so the HU genre list showed Drama and Dráma.
plex/genres.py maps every genre word to one Hungarian word; the overlay writes it
into genres_hu for every row, and a HU genre filter is read through the same map,
so a saved filter still holding Action keeps matching.
2026-09-29 01:52:02 +02:00

101 lines
3.5 KiB
Python

"""One Hungarian word per Plex genre (E30).
Plex's Hungarian agent returns a MIXED vocabulary: some genres come back translated ("Dráma",
"Vígjáték"), others stay English ("Action", "Adventure", "Biography"), and a title with no HU twin has
only its English genres. The HU genre list therefore offered "Drama" beside "Dráma" and a dozen English
words. This map sends every genre word we have met — English (Plex EN agent, TMDB, IMDb) or Plex's
Hungarian — to the ONE word a Hungarian reader sees. The overlay sync writes it into `genres_hu`, and a
genre filter is read through it too, so a saved filter still holding "Action" keeps matching "Akció".
A word not in the map passes through unchanged: an unknown genre stays visible (in whatever language
Plex gave it) rather than disappearing.
"""
from collections.abc import Iterable
# Keys are matched case-insensitively (see `_BY_KEY`). The Hungarian values double as keys mapping to
# themselves, so running a list through twice changes nothing.
_HU: dict[str, str] = {
"Action": "Akció",
"Action & Adventure": "Akció és kaland",
"Adventure": "Kaland",
"Animation": "Animációs",
"Anime": "Anime",
"Biography": "Életrajzi",
"Children": "Gyerek",
"Comedy": "Vígjáték",
"Crime": "Bűnügyi",
"Documentary": "Dokumentum",
"Drama": "Dráma",
"Family": "Családi",
"Fantasy": "Fantasy",
"Film-Noir": "Film noir",
"Food": "Gasztronómia",
"Game Show": "Vetélkedő",
"Game-Show": "Vetélkedő",
"History": "Történelmi",
"Home and Garden": "Otthon és kert",
"Horror": "Horror",
"Indie": "Független",
"Kids": "Gyerek",
"Martial Arts": "Harcművészet",
"Mini-Series": "Minisorozat",
"Music": "Zenei",
"Musical": "Musical",
"Mystery": "Rejtély",
"News": "Hírek",
"Reality": "Valóságshow",
"Reality-TV": "Valóságshow",
"Romance": "Romantikus",
"Sci-Fi": "Sci-Fi",
"Sci-Fi & Fantasy": "Sci-Fi és fantasy",
"Science Fiction": "Sci-Fi",
"Short": "Rövidfilm",
"Soap": "Szappanopera",
"Sport": "Sport",
"Suspense": "Feszültség",
"Talk": "Talkshow",
"Talk Show": "Talkshow",
"Thriller": "Thriller",
"Travel": "Utazás",
"TV Movie": "TV film",
"War": "Háborús",
"War & Politics": "Háború és politika",
"Western": "Western",
# Plex's own Hungarian words, pinned to themselves (and to the spelling above where they differ).
"Akció": "Akció",
"Animációs": "Animációs",
"Bűnügyi": "Bűnügyi",
"Családi": "Családi",
"Dokumentum": "Dokumentum",
"Dokumentumfilm": "Dokumentum",
"Dráma": "Dráma",
"Életrajzi": "Életrajzi",
"Háborús": "Háborús",
"Kaland": "Kaland",
"Rejtély": "Rejtély",
"Romantikus": "Romantikus",
"Történelmi": "Történelmi",
"TV film": "TV film",
"Vígjáték": "Vígjáték",
"Zene": "Zenei",
"Zenei": "Zenei",
}
_BY_KEY = {k.casefold(): v for k, v in _HU.items()}
def hu_genre(word: str) -> str:
"""The Hungarian word for one genre; an unknown word comes back unchanged."""
return _BY_KEY.get(word.strip().casefold(), word)
def hu_genres(words: Iterable[str] | None) -> list[str] | None:
"""A genre list in Hungarian, in its first-seen order, each word once ("Drama" + "Dráma" → one
"Dráma"). None or empty stays None, like the listing's own `_tags`."""
out: list[str] = []
for w in words or ():
hu = hu_genre(w)
if hu not in out:
out.append(hu)
return out or None