E5 S6 backend half (no migration — the *_hu / rich columns exist from S5a/S5b). Language-aware serving (?lang=hu serves the HU overlay twin, EN fallback per row): - query.py: column pickers title_col / genres_col / vector_col; field_recheck and meta_filter_conds take `lang`. DISPLAY/FILTER pickers coalesce(*_hu, *) (EN fallback); SEARCH pickers use the raw *_hu column mirroring the generated search_vector_hu (coalesce to '', not EN) so the field recheck stays a strict subset of the GIN vector (the S2 invariant). genres_col type_coerces the coalesce to JSONB so the GIN `.contains` survives. - browse.py: `lang` param on /library, /facets, /item, /show (validated to en|hu). unified_library title/vector/rank/field-scope + meta filters are language-aware for both the movie and show branches; facets unnest the active-language genre vocabulary (jsonb_typeof guard kept); detail endpoints serve HU title/summary/ genres/show_title with EN fallback. Episodes stay EN (not overlay-localized). IMDb-only rating (folded-in S5b review #5): - detail.py rich_detail: drop the audienceRating/rating fallback → imdb_rating is NULL when there's no imdb:// Rating entry (stop mislabelling a Plex audience score as IMDb). item_detail now also serves the `rating` column (audience score; show_detail already did) so the UI can show it when there's no IMDb score. Tests: test_plex_lang.py (HU title serving + EN fallback, language-specific facet vocabulary, genre-filter language matching, item_detail lang + rating split); test_plex_detail updated for IMDb-only. DB-lane suite 293 passed / 2 skipped; ruff clean.
60 lines
2.9 KiB
Python
60 lines
2.9 KiB
Python
"""Parse the "info page" rich metadata out of a full Plex metadata dict, and persist the subset that
|
|
the detail endpoints serve from the DB row (E5 S5b).
|
|
|
|
Shared by the live info-page path (routes.plex.browse) and the background rich re-sync (plex.sync) so
|
|
the two never diverge — the same one-parser rule that keeps `people.py`'s cast handling consistent.
|
|
`rich_detail` is the pure parser; `apply_rich_detail` writes the rich-ONLY fields onto a movie/show row
|
|
(genres/directors/studio/content_rating already land from the cheap listing at `_apply_facet_fields`)."""
|
|
|
|
from app.plex import people
|
|
|
|
|
|
def rich_detail(meta: dict) -> dict:
|
|
"""Pull the info-page extras out of a full Plex metadata dict: an IMDb score + link, content
|
|
rating, genres, director(s), studio, tagline, and cast (name/role/photo). Best-effort — any
|
|
missing field is just omitted."""
|
|
# Rating: IMDb-ONLY — the explicit `imdb://` entry in the Rating array, or NULL. We deliberately do
|
|
# NOT fall back to audienceRating/rating here: that is a Plex audience score, not an IMDb score, and
|
|
# labelling it "imdb_rating" mislabels it. The audience score is served separately (item/show detail
|
|
# expose the `rating` column) so the UI can show it when there's no IMDb score.
|
|
imdb_rating = None
|
|
for r in meta.get("Rating") or []:
|
|
if str(r.get("image") or "").startswith("imdb://"):
|
|
try:
|
|
imdb_rating = round(float(r.get("value")), 1)
|
|
except (TypeError, ValueError):
|
|
pass
|
|
break
|
|
# IMDb id (tt…) from the Guid list → a clickable link.
|
|
imdb_id = None
|
|
for g in meta.get("Guid") or []:
|
|
gid = str(g.get("id") or "")
|
|
if gid.startswith("imdb://"):
|
|
imdb_id = gid.split("imdb://", 1)[1]
|
|
break
|
|
return {
|
|
"imdb_rating": imdb_rating,
|
|
"imdb_id": imdb_id,
|
|
"imdb_url": f"https://www.imdb.com/title/{imdb_id}/" if imdb_id else None,
|
|
"content_rating": meta.get("contentRating"),
|
|
"genres": [g.get("tag") for g in (meta.get("Genre") or []) if g.get("tag")][:8],
|
|
"directors": [
|
|
d.get("tag") for d in (meta.get("Director") or []) if d.get("tag")
|
|
][:4],
|
|
"studio": meta.get("studio"),
|
|
"tagline": meta.get("tagline"),
|
|
"cast": people.cast_from_meta(meta),
|
|
}
|
|
|
|
|
|
def apply_rich_detail(row, meta: dict) -> None:
|
|
"""Persist the rich-ONLY detail fields onto a movie/show row so the info page serves them from the
|
|
DB instead of a live Plex call. Call wherever a rich metadata dict is fetched (the cast backfill +
|
|
the info-page lazy enrich). Empty cast persists as SQL NULL (none_as_null), so an EN fallback and
|
|
the `full_cast IS NULL` "not yet enriched" signal stay meaningful."""
|
|
d = rich_detail(meta)
|
|
row.imdb_rating = d["imdb_rating"]
|
|
row.imdb_id = d["imdb_id"]
|
|
row.tagline = d["tagline"]
|
|
row.full_cast = d["cast"] or None
|