diff options
| author | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-06 16:23:59 -0700 |
|---|---|---|
| committer | Tyler Hoang <tyler@tylerhoang.xyz> | 2026-05-06 16:23:59 -0700 |
| commit | 138eaaa12cdaeb6035951ff4f1547d73e8d12612 (patch) | |
| tree | 4337312e2a7dfa7dc1f6a4a4f5088771b57591ee /services/tmdb.py | |
| parent | 44627e1fec2d5e11179d8ce07fff95635a6633a2 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'services/tmdb.py')
| -rw-r--r-- | services/tmdb.py | 31 |
1 files changed, 31 insertions, 0 deletions
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 = { |
