summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/media_cache.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/media_cache.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/media_cache.py35
1 files changed, 35 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 129927d..6daae3f 100644
--- a/packages/meshbay-node/src/meshbay_node/media_cache.py
+++ b/packages/meshbay-node/src/meshbay_node/media_cache.py
@@ -41,6 +41,13 @@ CREATE TABLE IF NOT EXISTS thumbs (
jpeg BLOB NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_thumbs_file ON thumbs(file_id);
+CREATE TABLE IF NOT EXISTS season_meta (
+ tmdb_id TEXT NOT NULL,
+ season INTEGER NOT NULL,
+ json TEXT NOT NULL,
+ fetched_at REAL NOT NULL,
+ PRIMARY KEY (tmdb_id, season)
+);
"""
# TMDB overviews/ratings do drift; a file's own resolved tmdb_id does not
@@ -109,6 +116,34 @@ class MediaCache:
)
await self._db.commit()
+ # ── tmdb id + season number -> season-level metadata json ────────────────
+ #
+ # A show's own overview (tmdb_meta above) is one static field an operator
+ # found does not necessarily describe every season alike (mediacenter.md
+ # §5.4) — this is TMDB's per-season `overview`/`air_date`/`poster_path`,
+ # fetched and cached independently, on the same staleness schedule.
+
+ async def get_season_meta(self, tmdb_id: str, season: int) -> dict | None:
+ async with self._db.execute(
+ "SELECT json, fetched_at FROM season_meta WHERE tmdb_id = ? AND season = ?",
+ (tmdb_id, season),
+ ) as cur:
+ row = await cur.fetchone()
+ if not row:
+ return None
+ raw_json, fetched_at = row
+ if time.time() - fetched_at > TMDB_META_TTL_SECS:
+ return None
+ return json.loads(raw_json)
+
+ async def set_season_meta(self, tmdb_id: str, season: int, meta: dict) -> None:
+ await self._db.execute(
+ "INSERT OR REPLACE INTO season_meta (tmdb_id, season, json, fetched_at) "
+ "VALUES (?, ?, ?, ?)",
+ (tmdb_id, season, json.dumps(meta), time.time()),
+ )
+ await self._db.commit()
+
# ── thumbnails ────────────────────────────────────────────────────────────
async def get_thumb(self, thumb_hash: str) -> bytes | None: