From fb395004288aec78b5222606793720e5a750dfe8 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 21 Nov 2023 21:10:34 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E4=BC=98=E5=8C=96=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=BB=93=E5=BA=93URL=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- app/helper/plugin.py | 32 +++++++++++++++++++++++++------- config/app.env | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 58bb3ab5..774c6050 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ MoviePilot需要配套下载器和媒体服务器配合使用。 - **AUTO_DOWNLOAD_USER:** 远程交互搜索时自动择优下载的用户ID(消息通知渠道的用户ID),多个用户使用,分割,未设置需要选择资源或者回复`0` --- - **OCR_HOST:** OCR识别服务器地址,格式:`http(s)://ip:port`,用于识别站点验证码实现自动登录获取Cookie等,不配置默认使用内建服务器`https://movie-pilot.org`,可使用 [这个镜像](https://hub.docker.com/r/jxxghp/moviepilot-ocr) 自行搭建。 -- **PLUGIN_MARKET:** 插件市场仓库地址,多个地址使用`,`分隔,保留最后的/,默认为官方插件仓库:`https://raw.githubusercontent.com/jxxghp/MoviePilot-Plugins/main/`。 +- **PLUGIN_MARKET:** 插件市场仓库地址,仅支持Github仓库,`main`分支,多个地址使用`,`分隔,保留最后的/,默认为官方插件仓库:`https://github.com/jxxghp/MoviePilot-Plugins/ `。 - **GITHUB_TOKEN:** Github token,提高请求api限流阈值 ghp_****(仅支持环境变量配置) --- - **❗MESSAGER:** 消息通知渠道,支持 `telegram`/`wechat`/`slack`/`synologychat`,开启多个渠道时使用`,`分隔。同时还需要配置对应渠道的环境变量,非对应渠道的变量可删除,推荐使用`telegram` diff --git a/app/helper/plugin.py b/app/helper/plugin.py index 9f867ba5..a24e9123 100644 --- a/app/helper/plugin.py +++ b/app/helper/plugin.py @@ -16,6 +16,8 @@ class PluginHelper(metaclass=Singleton): 插件市场管理,下载安装插件到本地 """ + _base_url = "https://raw.githubusercontent.com/%s/%s/main/" + @cached(cache=TTLCache(maxsize=10, ttl=1800)) def get_plugins(self, repo_url: str) -> Dict[str, dict]: """ @@ -24,27 +26,43 @@ class PluginHelper(metaclass=Singleton): """ if not repo_url: return {} + user, repo = self.get_repo_info(repo_url) + if not user or not repo: + return {} + raw_url = self._base_url % (user, repo) res = RequestUtils(proxies=settings.PROXY, headers=settings.GITHUB_HEADERS, - timeout=10).get_res(f"{repo_url}package.json") + timeout=10).get_res(f"{raw_url}package.json") if res: return json.loads(res.text) return {} @staticmethod - def install(pid: str, repo_url: str) -> Tuple[bool, str]: + def get_repo_info(repo_url: str) -> Tuple[Optional[str], Optional[str]]: """ - 安装插件 + 获取Github仓库信息 + :param repo_url: Github仓库地址 """ - # 从Github的repo_url获取用户和项目名 + if not repo_url: + return None, None try: user, repo = repo_url.split("/")[-4:-2] except Exception as e: - return False, f"不支持的插件仓库地址格式:{str(e)}" - if not user or not repo: - return False, "不支持的插件仓库地址格式" + print(str(e)) + return None, None + return user, repo + + def install(self, pid: str, repo_url: str) -> Tuple[bool, str]: + """ + 安装插件 + """ if SystemUtils.is_frozen(): return False, "可执行文件模式下,只能安装本地插件" + # 从Github的repo_url获取用户和项目名 + user, repo = self.get_repo_info(repo_url) + if not user or not repo: + return False, "不支持的插件仓库地址格式" + def __get_filelist(_p: str) -> Tuple[Optional[list], Optional[str]]: """ 获取插件的文件列表 diff --git a/config/app.env b/config/app.env index 0aa6accf..6616a2cb 100644 --- a/config/app.env +++ b/config/app.env @@ -194,5 +194,5 @@ PLEX_TOKEN= # OCR服务器地址 OCR_HOST=https://movie-pilot.org # 插件市场仓库地址,多个地址使用`,`分隔,保留最后的/ -PLUGIN_MARKET=https://raw.githubusercontent.com/jxxghp/MoviePilot-Plugins/main/ +PLUGIN_MARKET=https://github.com/jxxghp/MoviePilot-Plugins/