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/tests/test_rename_reenrichment.py | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'packages/meshbay-node/tests/test_rename_reenrichment.py') diff --git a/packages/meshbay-node/tests/test_rename_reenrichment.py b/packages/meshbay-node/tests/test_rename_reenrichment.py index 87e0d1a..7a77368 100644 --- a/packages/meshbay-node/tests/test_rename_reenrichment.py +++ b/packages/meshbay-node/tests/test_rename_reenrichment.py @@ -22,6 +22,7 @@ from meshbay_common.crypto import generate_gek from meshbay_node.config import Config, HubConfig, NodeConfig, GroupConfig, KeystoreConfig from meshbay_node.daemon import NodeDaemon from meshbay_node.indexer import DirectoryIndexer +from meshbay_node.media_cache import MediaCache from conftest import one_root @@ -115,6 +116,61 @@ async def test_a_renamed_file_gets_re_enriched(tmp_path): "from ever being title-parsed") +async def test_a_rename_drops_the_stale_cached_tmdb_match(tmp_path): + """ + A rename re-derives the title, which can change the correct TMDB match + — but media_cache.file_tmdb is keyed by content hash, unchanged by a + rename, so without an explicit clear the old name's match sticks + forever. (An explicit "Fix match" correction is kept — covered by + test_media_cache.py's clear_file_tmdb tests.) + """ + group_id = "a" * 32 + shared = tmp_path / "shared" + shared.mkdir() + old_path = shared / "old.frontier.3.2001.mkv" + old_path.write_bytes(b"not a real video, just needs to be indexed as one") + + config = Config( + hub=HubConfig(url="http://localhost:9999", username="testuser"), + node=NodeConfig(quic_port=_free_port(), ui_port=_free_port()), + groups=[GroupConfig( + id=group_id, name="test-group", shared_dir=str(shared), + visibility="private", quic_port=29018, + )], + keystore=KeystoreConfig(path=tmp_path / "keystore.enc"), + data_dir=tmp_path / "data", + ) + daemon = NodeDaemon(config) + daemon._broadcast_coalesce_secs = 0.01 + daemon._enricher = _SpyEnricher() + daemon._roster = _StubRoster() + media_cache = MediaCache(db_path=tmp_path / "media_cache.db") + await media_cache.open() + daemon._media_cache = media_cache + + indexer = DirectoryIndexer( + roots=one_root(shared), group_id=group_id, + sk_node=Ed25519PrivateKey.generate(), gek=generate_gek(), + on_change=daemon._on_index_change) + await indexer.initial_scan() + await daemon._on_index_change(indexer) + await asyncio.sleep(0.05) + + file_id = next(iter(indexer.index.entries)).id + await media_cache.set_file_tmdb(file_id, "201", "movie") # the wrong match + + old_path.rename(shared / "old.frontier.iii.2001.mkv") + assert await indexer.reconcile() + for _ in range(30): + if await media_cache.get_file_tmdb(file_id) is None: + break + await asyncio.sleep(0.02) + + assert await media_cache.get_file_tmdb(file_id) is None, ( + "a rename must drop the auto-resolved match so it re-resolves") + await media_cache.close() + + async def test_an_unrelated_update_does_not_re_trigger_enrichment(tmp_path): """ The other half of the same fix: an update whose name/path did *not* -- cgit v1.2.3