From bab762ea395b1b9bd73df3bafa35611b36120507 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Mon, 9 Mar 2026 04:18:25 -0400 Subject: [PATCH] Reapply "[O] Use imdbapi instead" This reverts commit 873762945b5b352853d221fea2a6f2c862ab821f. --- utils_imdb.py | 31 +++++++++++++++++++++++++++++++ workflow.py | 12 ++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 utils_imdb.py diff --git a/utils_imdb.py b/utils_imdb.py new file mode 100644 index 0000000..bdac150 --- /dev/null +++ b/utils_imdb.py @@ -0,0 +1,31 @@ +import json +import urllib.request +import urllib.parse +from utils import with_disk_cache + +@with_disk_cache('imdbapi_info') +def get_imdb_info(imdb_id: str) -> dict: + """ + Fetch IMDb info from imdbapi.dev as a fallback or replacement for M-Team. + """ + query = urllib.parse.quote(imdb_id) + url = f"https://api.imdbapi.dev/search/titles?query={query}" + + req = urllib.request.Request(url, headers={ + 'accept': 'application/json', + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0' + }) + + try: + with urllib.request.urlopen(req) as response: + data = json.loads(response.read().decode()) + if data and "titles" in data and len(data["titles"]) > 0: + # Return the matching title info + for title in data["titles"]: + if title.get("id") == imdb_id: + return {"code": "0", "message": "SUCCESS", "data": title} + return {"code": "0", "message": "SUCCESS", "data": data["titles"][0]} + except Exception as e: + print(f"Error fetching from imdbapi for {imdb_id}: {e}") + + return {"code": "1", "message": "NOT_FOUND", "data": {}} diff --git a/workflow.py b/workflow.py index 2a4f429..fb58791 100644 --- a/workflow.py +++ b/workflow.py @@ -3,11 +3,11 @@ import time from pathlib import Path from utils_mteam import ( - mteam_imdb_info, search_mteam_torrents, format_mteam_torrent, generate_mteam_download_token, ) +from utils_imdb import get_imdb_info from utils_qb import ( get_qb_client, download_torrent, @@ -87,12 +87,12 @@ def process_imdb_workflow(imdb_id: str, dl_dir: str = "/data/QB", jellyfin_base_ Workflow to automatically find, download, and map torrents for an IMDb ID into a Jellyfin library. """ print(f"=== [0] Fetching IMDB info for {imdb_id} ===") - imdb_info = mteam_imdb_info(imdb_id) - if 'data' not in imdb_info: - raise ValueError(f"Failed to get IMDB info from M-Team: {imdb_info}") + imdb_info = get_imdb_info(imdb_id) + if 'data' not in imdb_info or not imdb_info['data']: + raise ValueError(f"Failed to get IMDB info from imdbapi: {imdb_info}") - title = imdb_info['data'].get('title', 'Unknown_Title') - year = imdb_info['data'].get('year', '') + title = imdb_info['data'].get('primaryTitle', 'Unknown_Title') + year = imdb_info['data'].get('startYear', '') title_dir = f"{title} ({year})" print(f"Found Title: {title_dir}")