diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-08-29 14:58:30 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-08-29 14:58:58 +0200 |
| commit | 71b7a310ce938f072fe20f27eeeadd40685f1ad1 (patch) | |
| tree | 75a7d93d58fda0e742dd9b1c94538b532c34464a /packages/meshbay-node/src/meshbay_node/media_cache.py | |
| parent | b7733e812fadd6007976d262bd1d793572a36ba7 (diff) | |
| download | meshbay-71b7a310ce938f072fe20f27eeeadd40685f1ad1.tar.gz | |
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018BMLQjqFGCize2KtNBT79v
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/media_cache.py')
| -rw-r--r-- | packages/meshbay-node/src/meshbay_node/media_cache.py | 49 |
1 files changed, 49 insertions, 0 deletions
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() |