weebzone commited on
Commit ·
084d77d
1
Parent(s): 1fc9b62
minor patch
Browse files- Backend/helper/imdb.py +40 -41
- Backend/helper/metadata.py +5 -8
Backend/helper/imdb.py
CHANGED
|
@@ -59,49 +59,48 @@ async def search_title(query: str, type: str) -> Optional[Dict[str, Any]]:
|
|
| 59 |
|
| 60 |
async def get_detail(imdb_id: str, media_type: str) -> Optional[Dict[str, Any]]:
|
| 61 |
client = await _get_client()
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
media_types = ["movie"]
|
| 67 |
-
|
| 68 |
-
for media_type in media_types:
|
| 69 |
-
try:
|
| 70 |
-
url = f"{BASE_URL}/meta/{media_type}/{imdb_id}.json"
|
| 71 |
-
resp = await client.get(url)
|
| 72 |
-
if resp.status_code != 200:
|
| 73 |
-
continue
|
| 74 |
-
data = resp.json()
|
| 75 |
-
if 'meta' not in data:
|
| 76 |
-
continue
|
| 77 |
-
meta = data['meta']
|
| 78 |
-
year_value = 0
|
| 79 |
-
for field in ['year', 'releaseInfo', 'released']:
|
| 80 |
-
if meta.get(field):
|
| 81 |
-
year_value = extract_first_year(meta[field])
|
| 82 |
-
if year_value:
|
| 83 |
-
break
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
async def get_season(imdb_id: str, season_id: int, episode_id: int) -> Optional[Dict[str, Any]]:
|
|
|
|
| 59 |
|
| 60 |
async def get_detail(imdb_id: str, media_type: str) -> Optional[Dict[str, Any]]:
|
| 61 |
client = await _get_client()
|
| 62 |
+
cinemeta_type = "series" if media_type in ["tvSeries", "tv"] else "movie"
|
| 63 |
|
| 64 |
+
try:
|
| 65 |
+
url = f"{BASE_URL}/meta/{cinemeta_type}/{imdb_id}.json"
|
| 66 |
+
resp = await client.get(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
if resp.status_code != 200:
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
data = resp.json()
|
| 72 |
+
meta = data.get("meta")
|
| 73 |
+
if not meta:
|
| 74 |
+
return None
|
| 75 |
+
|
| 76 |
+
# ---- Extract year ----
|
| 77 |
+
year_value = 0
|
| 78 |
+
for field in ["year", "releaseInfo", "released"]:
|
| 79 |
+
if meta.get(field):
|
| 80 |
+
year_value = extract_first_year(meta[field])
|
| 81 |
+
if year_value:
|
| 82 |
+
break
|
| 83 |
+
|
| 84 |
+
return {
|
| 85 |
+
"id": meta.get("imdb_id") or meta.get("id"),
|
| 86 |
+
"moviedb_id": meta.get("moviedb_id"),
|
| 87 |
+
"type": meta.get("type", media_type),
|
| 88 |
+
"title": meta.get("name", ""),
|
| 89 |
+
"plot": meta.get("description", ""),
|
| 90 |
+
"genre": meta.get("genres") or meta.get("genre", []),
|
| 91 |
+
"releaseDetailed": {"year": year_value},
|
| 92 |
+
"rating": {"star": float(meta.get("imdbRating", 0) or 0)},
|
| 93 |
+
"poster": meta.get("poster", ""),
|
| 94 |
+
"background": meta.get("background", ""),
|
| 95 |
+
"logo": meta.get("logo", ""),
|
| 96 |
+
"runtime": meta.get("runtime") or 0,
|
| 97 |
+
"director": meta.get("director", []),
|
| 98 |
+
"cast": meta.get("cast", []),
|
| 99 |
+
"videos": meta.get("videos", [])
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
except Exception:
|
| 103 |
+
return None
|
| 104 |
|
| 105 |
|
| 106 |
async def get_season(imdb_id: str, season_id: int, episode_id: int) -> Optional[Dict[str, Any]]:
|
Backend/helper/metadata.py
CHANGED
|
@@ -57,6 +57,7 @@ def format_imdb_images(imdb_id: str) -> dict:
|
|
| 57 |
}
|
| 58 |
|
| 59 |
def extract_default_id(url: str) -> str | None:
|
|
|
|
| 60 |
# IMDb
|
| 61 |
imdb_match = re.search(r'/title/(tt\d+)', url)
|
| 62 |
if imdb_match:
|
|
@@ -188,7 +189,7 @@ async def metadata(filename: str, channel: int, msg_id) -> dict | None:
|
|
| 188 |
LOGGER.info(f"No title parsed from: {filename} (parsed={parsed})")
|
| 189 |
return None
|
| 190 |
|
| 191 |
-
|
| 192 |
default_id = None
|
| 193 |
try:
|
| 194 |
default_id = extract_default_id(Backend.USE_DEFAULT_ID)
|
|
@@ -257,9 +258,7 @@ async def fetch_tv_metadata(title, season, episode, encoded_string, year=None, q
|
|
| 257 |
use_tmdb = True
|
| 258 |
|
| 259 |
# TMDb fallback
|
| 260 |
-
|
| 261 |
-
if must_use_tmdb:
|
| 262 |
-
LOGGER.info(f"No IMDb result for '{title}' switch to TMDb")
|
| 263 |
if not tmdb_id:
|
| 264 |
tmdb_result = await safe_tmdb_search(title, "tv")
|
| 265 |
if not tmdb_result:
|
|
@@ -365,9 +364,7 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 365 |
LOGGER.warning(f"IMDb movie fetch failed [{title}]: {e}")
|
| 366 |
use_tmdb = True
|
| 367 |
|
| 368 |
-
|
| 369 |
-
if must_use_tmdb:
|
| 370 |
-
LOGGER.info(f"No IMDb movie found for '{title}' switch to TMDb")
|
| 371 |
if not tmdb_id:
|
| 372 |
tmdb_result = await safe_tmdb_search(title, "movie", year)
|
| 373 |
if not tmdb_result:
|
|
@@ -422,4 +419,4 @@ async def fetch_movie_metadata(title, encoded_string, year=None, quality=None, d
|
|
| 422 |
"genres": movie_details.get("genre", []),
|
| 423 |
"quality": quality,
|
| 424 |
"encoded_string": encoded_string,
|
| 425 |
-
}
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
def extract_default_id(url: str) -> str | None:
|
| 60 |
+
"""Extract IMDb or TMDb ID from string."""
|
| 61 |
# IMDb
|
| 62 |
imdb_match = re.search(r'/title/(tt\d+)', url)
|
| 63 |
if imdb_match:
|
|
|
|
| 189 |
LOGGER.info(f"No title parsed from: {filename} (parsed={parsed})")
|
| 190 |
return None
|
| 191 |
|
| 192 |
+
# Extract default ID
|
| 193 |
default_id = None
|
| 194 |
try:
|
| 195 |
default_id = extract_default_id(Backend.USE_DEFAULT_ID)
|
|
|
|
| 258 |
use_tmdb = True
|
| 259 |
|
| 260 |
# TMDb fallback
|
| 261 |
+
if use_tmdb or (tmdb_id and not tv_details):
|
|
|
|
|
|
|
| 262 |
if not tmdb_id:
|
| 263 |
tmdb_result = await safe_tmdb_search(title, "tv")
|
| 264 |
if not tmdb_result:
|
|
|
|
| 364 |
LOGGER.warning(f"IMDb movie fetch failed [{title}]: {e}")
|
| 365 |
use_tmdb = True
|
| 366 |
|
| 367 |
+
if use_tmdb or (tmdb_id and not movie_details):
|
|
|
|
|
|
|
| 368 |
if not tmdb_id:
|
| 369 |
tmdb_result = await safe_tmdb_search(title, "movie", year)
|
| 370 |
if not tmdb_result:
|
|
|
|
| 419 |
"genres": movie_details.get("genre", []),
|
| 420 |
"quality": quality,
|
| 421 |
"encoded_string": encoded_string,
|
| 422 |
+
}
|