114 exception handlers neither logged nor re-raised. The defect was never that
they are silent — plenty of them should be — it is that their silence said
nothing, so nobody could tell a decision from an oversight. Each one has now been
read. 44 got a line; the other 70 carry `# silent-ok: <why>`.
What the silent ones had been hiding, in the cases that got a line:
- A failed ffprobe sent every HDR file down the 8-bit pipeline, so playback
degraded to a software transcode with nothing saying why; a failed audio probe
collapsed a multi-audio file to one track and the player showed no language
picker; a failed first-PTS probe left subtitles seconds out of sync.
- A subtitle sidecar that existed but would not parse made a PARTIAL track read as
complete, permanently — the viewer loses every cue past the cached window.
- An unreadable crop/trim/cut-list in an edit spec was dropped, so the clip came
out uncropped, untrimmed, or shorter than the one the user built.
- A dropped `max_height` downloaded at best quality against an explicit cap.
- A failed videos.list enrich made every candidate undroppable-from-judgement and
therefore dropped: a working search rendered as "no results".
- An unusable password hash answered as "wrong password", locking the owner out
and telling them they mistyped; a rotated TOKEN_ENCRYPTION_KEY turned every
stored token into "not connected".
- A stored admin setting that would not coerce fell back to the env default while
the settings page went on showing the saved value.
- A one-off InnerTube config failure pinned the whole process to the hard-coded
fallback key, and searches return nothing when that goes stale.
- The HLS sweep reported 0 swept — like a clean run — when it could not list its
own root, leaving every crashed session's segments on disk forever.
Four of them are counted rather than logged per item (dropped cues, dropped cut
list segments, unreclaimed GC files) and reported once per call, because the
alternative is one line per cue over a whole subtitle track.
ruff gains S110 and BLE001. Every blind `except Exception` that remains carries
`# noqa: BLE001 — <why>`, which is the point: catching everything is sometimes
right, and always worth a sentence. plex/sync.py's three best-effort backfill
catches now keep the traceback — a blind catch over a batch that fetches AND
writes could be Plex, the database or our own bug, and `%s` of the exception told
them apart badly. main.py's boot-time log-level read likewise.
logs.event's `code` is positional-only now: `event("x", code=...)` was a TypeError,
and `code` is exactly the word a caller reaches for when the thing that failed has
one of its own.
tests/test_swallowed_exceptions.py is the wider rule ruff cannot see: a handler
that neither logs nor re-raises must say why. Both cases mutation-checked — a
marker removed and a log line removed each fail it, naming the handler.
60 lines
3.1 KiB
Python
60 lines
3.1 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)
|
|
# silent-ok: no IMDb score, which is the common and legitimate case — the UI has a
|
|
# separate audience score to fall back on and shows nothing if neither exists.
|
|
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
|