summaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/tmdb.py31
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 = {