diff options
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() |