From 71b7a310ce938f072fe20f27eeeadd40685f1ad1 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Sat, 29 Aug 2026 14:58:30 +0200 Subject: fix(node): correct TMDB movie matching, per-file overrides, rematch A batch of wrong poster-grid matches found live on a real library (2026-08-29): a two-volume film's second part matched the first; a numbered sequel matched a same-year making-of documentary; several entries of one franchise matched a single early entry whose localized TMDB title is the franchise name; one matched nothing. One mechanism: _tmdb_search returned the first candidate query whose title-similarity ratio merely cleared 0.6, before alternative_title / the Roman-numeral variant was ever tried. Matching: - title_parse: fold guessit's volume/part number back into display_title so the parts of a multi-part film stay distinct in the query, the card and the override. - _tmdb_search: keep a strong PASS 1 fast path (ratio >= 0.85, one request), otherwise score every candidate query and pick the best. A year-exact rescue lifts a sub-0.6 top hit to the confidence floor only when TMDB's own year-filtered result lands exactly on the filename's year. No local re-ranking of any single result list; no tmdb.py change. Fix match / rematch: - _admin_exec_tmdb_override: a movie override touches its own file only (guessit gives a whole franchise one display_title); a show override still fans out. Corrected files are marked in media_cache.tmdb_override. - media_cache: tmdb_override table; clear_file_tmdb / clear_tmdb_matches drop auto-resolved matches while sparing manual corrections. - ops.rematch_video + `meshbay-node video rematch` (loopback endpoint + CLI verb): re-resolve a group's video matches after a matcher fix. file_tmdb is keyed by content hash and otherwise only pruned on deletion, so nothing dislodged a cached match before. - a rename now drops the stale auto match too (daemon _reenrich_renamed_video_entries). UI: - VideoDetailModal shows the source filename and resolved TMDB id; an unmatched poster gets a badge (3 new video.* i18n keys x 10 locales). So a wrong match can actually be identified before hitting Fix match. docs/mediacenter.md 10.1 records this and the V8-V13 follow-up backlog (show-branch ladder, year-aware _best_match, wider sequel_variants, the 0.6-0.85 extra calls, movie grid merge, per-card rematch). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_018BMLQjqFGCize2KtNBT79v --- .../meshbay-node/src/meshbay_node/media_cache.py | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'packages/meshbay-node/src/meshbay_node/media_cache.py') diff --git a/packages/meshbay-node/src/meshbay_node/media_cache.py b/packages/meshbay-node/src/meshbay_node/media_cache.py index 707a046..4600a09 100644 --- a/packages/meshbay-node/src/meshbay_node/media_cache.py +++ b/packages/meshbay-node/src/meshbay_node/media_cache.py @@ -34,6 +34,14 @@ CREATE TABLE IF NOT EXISTS file_tmdb ( tmdb_id TEXT NOT NULL, media_type TEXT NOT NULL ); +-- Files whose match was set by an explicit operator "Fix match" +-- correction, not by the automatic matcher. `ops.rematch_video` and a +-- rename's re-enrichment wipe the *auto-resolved* file->tmdb mappings so +-- they re-resolve against the current matcher; a manual correction must +-- survive that, so it is recorded here and skipped. +CREATE TABLE IF NOT EXISTS tmdb_override ( + file_id TEXT PRIMARY KEY +); CREATE TABLE IF NOT EXISTS tmdb_meta ( tmdb_id TEXT NOT NULL, media_type TEXT NOT NULL, @@ -144,6 +152,46 @@ class MediaCache: ) await self._db.commit() + # ── manual "Fix match" corrections vs auto-resolved matches ────────────── + + async def mark_tmdb_override(self, file_id: str) -> None: + """Record that this file's current match is an explicit operator + correction — `clear_file_tmdb` / `clear_tmdb_matches` skip it.""" + await self._db.execute( + "INSERT OR IGNORE INTO tmdb_override (file_id) VALUES (?)", (file_id,)) + await self._db.commit() + + async def clear_file_tmdb(self, file_id: str) -> None: + """ + Drop one file's *auto-resolved* match. Used on rename: the new name + re-derives the title, so the old name's match no longer applies — + but file_tmdb is keyed by content hash, unchanged by a rename, so + nothing else would ever dislodge it. A manual "Fix match" + correction is kept: the content, hence what the operator corrected, + is the same. + """ + await self._db.execute( + "DELETE FROM file_tmdb WHERE file_id = ? AND file_id NOT IN " + "(SELECT file_id FROM tmdb_override)", (file_id,)) + await self._db.commit() + + async def clear_tmdb_matches(self, file_ids: list[str]) -> int: + """ + Drop the auto-resolved file->tmdb mappings for these files so the + next `media_meta_req` re-resolves each against the current matcher + (`ops.rematch_video`, run by the operator after a matcher/parser + fix). Manual "Fix match" corrections (`tmdb_override`) are left in + place. Returns the number of rows removed. + """ + if not self._db or not file_ids: + return 0 + marks = ",".join("?" * len(file_ids)) + cur = await self._db.execute( + f"DELETE FROM file_tmdb WHERE file_id IN ({marks}) AND file_id NOT IN " + "(SELECT file_id FROM tmdb_override)", file_ids) + await self._db.commit() + return cur.rowcount + # ── tmdb id -> metadata json ───────────────────────────────────────────── async def get_tmdb_meta(self, tmdb_id: str, media_type: str) -> dict | None: @@ -324,5 +372,6 @@ class MediaCache: await self._db.execute("DELETE FROM photo_meta WHERE file_id = ?", (file_id,)) await self._db.execute("DELETE FROM video_meta WHERE file_id = ?", (file_id,)) await self._db.execute("DELETE FROM file_tmdb WHERE file_id = ?", (file_id,)) + await self._db.execute("DELETE FROM tmdb_override WHERE file_id = ?", (file_id,)) await self._db.execute("DELETE FROM file_mbid WHERE file_id = ?", (file_id,)) await self._db.commit() -- cgit v1.2.3