From a8bcf0e608b305a32bc09ef86ed41bc5b7803ba2 Mon Sep 17 00:00:00 2001 From: wumode Date: Sat, 12 Jul 2025 13:41:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update(ImdbSource)=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.v2.json | 3 +- plugins.v2/imdbsource/__init__.py | 2 +- plugins.v2/imdbsource/imdbhelper.py | 94 +++++++++++++++++++---------- 3 files changed, 66 insertions(+), 33 deletions(-) diff --git a/package.v2.json b/package.v2.json index 058efbd..32c7001 100644 --- a/package.v2.json +++ b/package.v2.json @@ -435,11 +435,12 @@ "name": "IMDb源", "description": "让探索和推荐支持IMDb数据源。", "labels": "探索", - "version": "1.4.3", + "version": "1.4.4", "icon": "IMDb_IOS-OSX_App.png", "author": "wumode", "level": 1, "history": { + "v1.4.4": "更新数据源", "v1.4.3": "为仪表盘组件添加缓存", "v1.4.2": "优化小屏幕组件显示", "v1.4.1": "优化亮色主题显示", diff --git a/plugins.v2/imdbsource/__init__.py b/plugins.v2/imdbsource/__init__.py index db7674c..b242ba8 100644 --- a/plugins.v2/imdbsource/__init__.py +++ b/plugins.v2/imdbsource/__init__.py @@ -22,7 +22,7 @@ class ImdbSource(_PluginBase): # 插件图标 plugin_icon = "IMDb_IOS-OSX_App.png" # 插件版本 - plugin_version = "1.4.3" + plugin_version = "1.4.4" # 插件作者 plugin_author = "wumode" # 作者主页 diff --git a/plugins.v2/imdbsource/imdbhelper.py b/plugins.v2/imdbsource/imdbhelper.py index 40903ec..1bb7a9e 100644 --- a/plugins.v2/imdbsource/imdbhelper.py +++ b/plugins.v2/imdbsource/imdbhelper.py @@ -1,11 +1,14 @@ import re +from json import JSONDecodeError from typing import Optional, Any, Dict, Tuple, List from collections import OrderedDict from dataclasses import dataclass import json +import base64 import requests +from app.core.config import settings from app.log import logger from app.utils.http import RequestUtils from app.utils.common import retry @@ -37,9 +40,6 @@ class SearchState: class ImdbHelper: _official_endpoint = "https://caching.graphql.imdb.com/" - _hash_update_url = ("https://raw.githubusercontent.com/wumode/MoviePilot-Plugins/" - "refs/heads/imdbsource_assets/plugins.v2/imdbsource/imdb_hash.json") - _imdb_headers = { "Accept": "text/html,application/json,text/plain,*/*", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome" @@ -100,22 +100,72 @@ class ImdbHelper: return {'error': error} return data.get("data") + def get_github_file(self, repo: str, owner: str, file_path: str, branch: str = None) -> Optional[str]: + """ + 从GitHub仓库获取指定文本文件内容 + :param repo: 仓库名称 + :param owner: 仓库所有者 + :param file_path: 文件路径(相对于仓库根目录) + :param branch: 分支名称,默认为 None(使用默认分支) + :return: 文件内容字符串,若获取失败则返回 None + """ + api_url = f"https://api.github.com/repos/{owner}/{repo}/contents/{file_path}" + if branch: + api_url = f"{api_url}?ref={branch}" + response = RequestUtils(headers=settings.GITHUB_HEADERS).get_res( + api_url, + proxies=self._proxies + ) + if not response or response.status_code != 200: + return None + try: + data = response.json() + content_base64 = data['content'] + json_bytes = base64.b64decode(content_base64) + json_text = json_bytes.decode('utf-8') + except (TypeError, ValueError, KeyError, UnicodeDecodeError): + return None + return json_text + @cached(maxsize=1, ttl=6 * 3600) def __get_hash(self) -> Optional[dict]: """ - 根据IMDb hash使用 + 获取 IMDb hash """ - headers = { - "Accept": "text/html", - } - res = RequestUtils(headers=headers).get_res( - self._hash_update_url, - proxies=self._proxies + res = self.get_github_file( + 'MoviePilot-Plugins', + 'wumode', + '/plugins.v2/imdbsource/imdb_hash.json', + 'imdbsource_assets' ) if not res: logger.error("Error getting hash") return None - return res.json() + try: + hash_data = json.loads(res) + except JSONDecodeError: + return None + return hash_data + + @cached(maxsize=1, ttl=6 * 3600) + def __get_staff_picks(self) -> Optional[dict]: + """ + 获取 IMDb Staff Picks + """ + res = self.get_github_file( + 'MoviePilot-Plugins', + 'wumode', + '/plugins.v2/imdbsource/staff_picks.json', + 'imdbsource_assets' + ) + if not res: + logger.error("Error getting staff picks") + return None + try: + json_data = json.loads(res) + except JSONDecodeError: + return None + return json_data def __update_hash(self, force: bool = False) -> None: if force: @@ -322,26 +372,7 @@ class ImdbHelper: 'relatedconst': ['nm0424060', 'nm0991810'] } """ - url = 'https://www.imdb.com/imdbpicks/staff-picks/' - html = self._imdb_req.get(url) - if not html: - return None - pattern = r'"jsonData":"{.*?}"' - json_strings = re.findall(pattern, html) - if not json_strings: - return None - try: - json_data = json.loads(f"{{{json_strings[0]}}}") - if json_data and 'jsonData' in json_data: - data = json.loads(json_data['jsonData']) - if 'entries' in data: - entries = data['entries'] - for entry in entries: - entry['description'] = re.sub(r'\[(/?)[iI]]', r'<\1i>', entry.get('description', '')) - return entries - except Exception as e: - logger.error(f"Error parsing json: {e}") - return None + return self.__get_staff_picks().get('entries') def vertical_list_page_items(self, titles: Optional[List[str]] = None, @@ -412,3 +443,4 @@ class ImdbHelper: logger.error(f"Error querying VerticalListPageItems: {error}") return None return data + From bce2655c382b4428f80feabf7d0ccee6252468d4 Mon Sep 17 00:00:00 2001 From: wumode Date: Sat, 12 Jul 2025 13:56:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update(ImdbSource)=20=E6=9B=B4=E6=96=B0imdb?= =?UTF-8?q?helper.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins.v2/imdbsource/imdbhelper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins.v2/imdbsource/imdbhelper.py b/plugins.v2/imdbsource/imdbhelper.py index 1bb7a9e..addd559 100644 --- a/plugins.v2/imdbsource/imdbhelper.py +++ b/plugins.v2/imdbsource/imdbhelper.py @@ -135,7 +135,7 @@ class ImdbHelper: res = self.get_github_file( 'MoviePilot-Plugins', 'wumode', - '/plugins.v2/imdbsource/imdb_hash.json', + 'plugins.v2/imdbsource/imdb_hash.json', 'imdbsource_assets' ) if not res: @@ -155,7 +155,7 @@ class ImdbHelper: res = self.get_github_file( 'MoviePilot-Plugins', 'wumode', - '/plugins.v2/imdbsource/staff_picks.json', + 'plugins.v2/imdbsource/staff_picks.json', 'imdbsource_assets' ) if not res: @@ -372,7 +372,7 @@ class ImdbHelper: 'relatedconst': ['nm0424060', 'nm0991810'] } """ - return self.__get_staff_picks().get('entries') + return (self.__get_staff_picks() or {}).get('entries') def vertical_list_page_items(self, titles: Optional[List[str]] = None,