1.0.5 - regression in adding extra info (directors, etc)

This commit is contained in:
ponzischeme89
2026-01-18 21:14:14 +13:00
parent 56f87327b1
commit 5d712065b9
5 changed files with 161 additions and 50 deletions
+70
View File
@@ -124,6 +124,35 @@ class OMDbClient:
finally:
self._inflight.pop(key, None)
async def fetch_summary_by_imdb_id(self, imdb_id: str) -> Optional[dict]:
"""
Fetch summary from OMDb using a specific IMDb ID.
Args:
imdb_id: IMDb ID (e.g., tt1234567)
"""
if not imdb_id:
return None
key = f"imdb:{imdb_id.lower()}"
if key in self._inflight:
logger.debug("Awaiting inflight OMDb request: %s", key)
return await self._inflight[key]
loop = asyncio.get_running_loop()
future = loop.create_future()
self._inflight[key] = future
try:
result = await self._fetch_summary_by_imdb_id_internal(imdb_id)
future.set_result(result)
return result
except Exception as e:
future.set_exception(e)
raise
finally:
self._inflight.pop(key, None)
# -----------------------------
# Internal fetch logic
# -----------------------------
@@ -202,6 +231,47 @@ class OMDbClient:
logger.error("OMDb network error for '%s': %s", title, e)
return None
async def _fetch_summary_by_imdb_id_internal(self, imdb_id: str) -> Optional[dict]:
logger.info("Fetching OMDb summary for IMDb ID: %s", imdb_id)
async with self.semaphore:
await self.rate_limiter.wait()
params = {
"apikey": self.api_key,
"i": imdb_id,
"plot": "short",
}
session = await self._get_session()
start = time.monotonic()
try:
async with session.get(self.BASE_URL, params=params) as resp:
elapsed_ms = int((time.monotonic() - start) * 1000)
if resp.status != 200:
self._track(False, imdb_id, elapsed_ms)
logger.error("OMDb HTTP %s for IMDb ID '%s'", resp.status, imdb_id)
return None
data = await resp.json()
if data.get("Response") != "True":
self._track(False, imdb_id, elapsed_ms)
logger.warning("OMDb error for IMDb ID '%s': %s", imdb_id, data.get("Error"))
return None
self._track(True, imdb_id, elapsed_ms)
return self._parse_response(data)
except asyncio.TimeoutError:
logger.error("OMDb timeout for IMDb ID '%s'", imdb_id)
return None
except aiohttp.ClientError as e:
logger.error("OMDb network error for IMDb ID '%s': %s", imdb_id, e)
return None
# -----------------------------
# Helpers
# -----------------------------
+18 -1
View File
@@ -1206,7 +1206,24 @@ class SubtitleProcessor:
# (Do metadata fetch BEFORE acquiring lock to minimize lock hold time)
if title_override:
logger.info("Using provided title override for %s: %s", file_path.name, title_override.get("title"))
movie = title_override
movie = dict(title_override)
# If extra fields are missing, try to enrich from OMDb using IMDb ID.
missing_fields = ["director", "actors", "released", "genre"]
has_missing = any(
not movie.get(field) or movie.get(field) == "N/A"
for field in missing_fields
)
imdb_id = movie.get("imdb_id") or movie.get("imdbID")
if has_missing and imdb_id and self.omdb_client:
try:
enrichment = await self.omdb_client.fetch_summary_by_imdb_id(imdb_id)
if enrichment:
for field in missing_fields:
if not movie.get(field) or movie.get(field) == "N/A":
movie[field] = enrichment.get(field, movie.get(field))
except Exception as e:
logger.warning("Failed to enrich metadata for %s: %s", imdb_id, e)
else:
raw_name = file_path.stem
movie_name, year = self.extract_title_and_year(raw_name, strip_keywords=strip_keywords)