From 8b4495c857ee5bf28a3686963e7a42933c6158a7 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 9 Mar 2024 18:25:04 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=B8=8B=E8=BD=BD=E5=99=A8?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 2 +- app/core/config.py | 20 +++++++++++++++++++- app/modules/qbittorrent/__init__.py | 6 +++++- app/modules/transmission/__init__.py | 6 +++++- app/scheduler.py | 6 ++++++ 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/app/chain/download.py b/app/chain/download.py index 161405c0..061b0b6b 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -292,7 +292,7 @@ class DownloadChain(ChainBase): continue files_to_add.append({ "download_hash": _hash, - "downloader": settings.DOWNLOADER, + "downloader": settings.DEFAULT_DOWNLOADER, "fullpath": str(download_dir / _folder_name / file), "savepath": str(download_dir / _folder_name), "filepath": file, diff --git a/app/core/config.py b/app/core/config.py index 7286b0a6..4a1578c8 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -125,7 +125,7 @@ class Settings(BaseSettings): VOCECHAT_API_KEY: str = "" # VoceChat 频道ID VOCECHAT_CHANNEL_ID: str = "" - # 下载器 qbittorrent/transmission + # 下载器 qbittorrent/transmission,启用多个下载器时使用,分隔,只有第一个会被默认使用 DOWNLOADER: str = "qbittorrent" # 下载器监控开关 DOWNLOADER_MONITOR: bool = True @@ -362,6 +362,24 @@ class Settings(BaseSettings): } return {} + @property + def DEFAULT_DOWNLOADER(self): + """ + 默认下载器 + """ + if not self.DOWNLOADER: + return None + return self.DOWNLOADER.split(",")[0] + + @property + def DOWNLOADERS(self): + """ + 下载器列表 + """ + if not self.DOWNLOADER: + return [] + return self.DOWNLOADER.split(",") + def __init__(self, **kwargs): super().__init__(**kwargs) with self.CONFIG_PATH as p: diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 1e12b218..a0d07fd7 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -73,8 +73,12 @@ class QbittorrentModule(_ModuleBase): logger.error(f"获取种子名称失败:{e}") return "", 0 + # 不是默认下载器不处理 + if settings.DEFAULT_DOWNLOADER != "qbittorrent": + return None + if not content: - return + return None if isinstance(content, Path) and not content.exists(): return None, f"种子文件不存在:{content}" diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index 357b6e67..6dfe7fbc 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -73,8 +73,12 @@ class TransmissionModule(_ModuleBase): logger.error(f"获取种子名称失败:{e}") return "", 0 + # 不是默认下载器不处理 + if settings.DEFAULT_DOWNLOADER != "transmission": + return None + if not content: - return + return None if isinstance(content, Path) and not content.exists(): return None, f"种子文件不存在:{content}" diff --git a/app/scheduler.py b/app/scheduler.py index 70b4c04c..044c5534 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -290,6 +290,8 @@ class Scheduler(metaclass=Singleton): """ 更新插件定时服务 """ + if not self._scheduler: + return # 移除该插件的全部服务 self.remove_plugin_job(pid) # 获取插件服务列表 @@ -332,6 +334,8 @@ class Scheduler(metaclass=Singleton): """ 移除插件定时服务 """ + if not self._scheduler: + return with self._lock: # 获取插件名称 plugin_name = PluginManager().get_plugin_attr(pid, "plugin_name") @@ -351,6 +355,8 @@ class Scheduler(metaclass=Singleton): """ 当前所有任务 """ + if not self._scheduler: + return [] with self._lock: # 返回计时任务 schedulers = []