From ead38fdb13abb406065cef0743d7e411cb27eaf3 Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Wed, 6 May 2026 18:05:07 -0700 Subject: Add genre tracking and year-in-review improvements Adds genre field to Film model with TMDB enrichment. Genres populate from TMDB detail fetch during add/edit and bulk enrichment. Genre metadata displays on film cards, detail page (Production section), stats page (top genres panel), and year-in-review (by decade and genre breakdowns). Auto-detects rewatches when adding films via TMDB autocomplete - if a film with the same TMDB ID already exists in diary, pre-fills rewatch checkbox and count. Rewatch count now displays on film cards as "Rewatch #N". Stats page now shows: - Top genres (most watched) - Film decades (sorted chronologically) - Already shows: directors, companions, star distribution, rewatch rate Year-in-review shows decades and genres alongside monthly activity and companions. Bulk enrichment endpoint (/data/enrich-posters) now fetches missing genre metadata along with posters and TMDB IDs. Co-Authored-By: Claude Haiku 4.5 --- routers/tmdb.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'routers/tmdb.py') diff --git a/routers/tmdb.py b/routers/tmdb.py index 5f7943f..f56a9df 100644 --- a/routers/tmdb.py +++ b/routers/tmdb.py @@ -3,7 +3,7 @@ from dotenv import load_dotenv from fastapi import APIRouter, Query from fastapi.responses import JSONResponse -from services.tmdb import TMDBNotConfiguredError, search_movies, movie_images +from services.tmdb import TMDBNotConfiguredError, search_movies, movie_images, movie_detail, movie_payload load_dotenv() @@ -32,6 +32,24 @@ async def search_tmdb(q: str = Query(..., min_length=2)): ) +@router.get("/detail/{tmdb_id}") +async def tmdb_detail(tmdb_id: int): + try: + async with httpx.AsyncClient(timeout=10.0) as client: + detail = await movie_detail(client, tmdb_id) + return movie_payload(detail) + except TMDBNotConfiguredError: + return JSONResponse( + status_code=503, + content={"error": "TMDB_API_KEY is not configured."}, + ) + except httpx.HTTPError: + return JSONResponse( + status_code=502, + content={"error": "Failed to fetch TMDB details."}, + ) + + @router.get("/posters") async def tmdb_posters(tmdb_id: int = Query(...)): try: -- cgit v1.3-2-g0d8e