From 138eaaa12cdaeb6035951ff4f1547d73e8d12612 Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Wed, 6 May 2026 16:23:59 -0700 Subject: Add director image and biography to director page - Fetch director profile image and biography from TMDB API - Display image next to director name with lazy loading - Show biography below director name - Gracefully handle missing data (image/biography optional) Co-Authored-By: Claude Haiku 4.5 --- services/tmdb.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'services') diff --git a/services/tmdb.py b/services/tmdb.py index b3adf17..e749f09 100644 --- a/services/tmdb.py +++ b/services/tmdb.py @@ -205,6 +205,37 @@ async def find_movie( await active_client.aclose() +async def director_info(director_name: str, key: str | None = None, client: httpx.AsyncClient | None = None) -> dict: + """Search for a director by name and return their image and biography.""" + try: + active_client = client + owns_client = False + if not active_client: + active_client = httpx.AsyncClient() + owns_client = True + + response = await active_client.get( + "https://api.themoviedb.org/3/search/person", + params={"api_key": key or api_key(), "query": director_name}, + ) + response.raise_for_status() + results = response.json().get("results", []) + + if not results: + return {"image": None, "biography": None} + + person = results[0] + image = poster_url(person.get("profile_path")) + biography = (person.get("biography") or "").strip() or None + + return {"image": image, "biography": biography} + except Exception: + return {"image": None, "biography": None} + finally: + if owns_client: + await active_client.aclose() + + def apply_metadata_to_film(film, metadata: dict) -> bool: changed = False fill_if_empty = { -- cgit v1.3-2-g0d8e