From f64363728ef5ffc217260e0c45a3e19074826317 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 8 Jul 2025 21:38:34 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E9=9D=99=E6=80=81=E7=B1=BB?= =?UTF-8?q?=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 32 +++++++++++++++----------------- app/core/event.py | 4 +--- app/core/meta/customization.py | 2 -- app/core/meta/releasegroup.py | 1 - app/core/module.py | 8 ++++---- app/core/plugin.py | 19 +++++++++---------- app/core/workflow.py | 5 ++--- app/helper/display.py | 1 - app/helper/doh.py | 3 +++ app/monitor.py | 29 +++++++++++++---------------- app/scheduler.py | 26 +++++++++++++------------- 11 files changed, 60 insertions(+), 70 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index bc11c308..e439e12b 100755 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -5,7 +5,6 @@ import threading import traceback from copy import deepcopy from pathlib import Path -from queue import Queue from time import sleep from typing import List, Optional, Tuple, Union, Dict, Callable @@ -16,9 +15,9 @@ from app.chain.storage import StorageChain from app.chain.tmdb import TmdbChain from app.core.config import settings, global_vars from app.core.context import MediaInfo +from app.core.event import eventmanager from app.core.meta import MetaBase from app.core.metainfo import MetaInfoPath -from app.core.event import eventmanager from app.db.downloadhistory_oper import DownloadHistoryOper from app.db.models.downloadhistory import DownloadHistory from app.db.models.transferhistory import TransferHistory @@ -28,11 +27,11 @@ from app.helper.directory import DirectoryHelper from app.helper.format import FormatParser from app.helper.progress import ProgressHelper from app.log import logger +from app.schemas import StorageOperSelectionEventData from app.schemas import TransferInfo, TransferTorrent, Notification, EpisodeFormat, FileItem, TransferDirectoryConf, \ TransferTask, TransferQueue, TransferJob, TransferJobTask from app.schemas.types import TorrentStatus, EventType, MediaType, ProgressKey, NotificationType, MessageChannel, \ SystemConfigKey, ChainEventType, ContentType -from app.schemas import StorageOperSelectionEventData from app.utils.singleton import Singleton from app.utils.string import StringUtils @@ -213,6 +212,7 @@ class JobManager: set(self._season_episodes[mediaid]) - set(task.meta.episode_list) ) return task + return None def remove_job(self, task: TransferTask) -> Optional[TransferJob]: """ @@ -226,6 +226,7 @@ class JobManager: if __mediaid__ in self._season_episodes: self._season_episodes.pop(__mediaid__) return self._job_view.pop(__mediaid__) + return None def is_done(self, task: TransferTask) -> bool: """ @@ -359,22 +360,18 @@ class TransferChain(ChainBase, metaclass=Singleton): 文件整理处理链 """ - # 可处理的文件后缀 - all_exts = settings.RMT_MEDIAEXT - - # 待整理任务队列 - _queue = Queue() - - # 文件整理线程 - _transfer_thread = None - - # 队列间隔时间(秒) - _transfer_interval = 15 - def __init__(self): super().__init__() + # 可处理的文件后缀 + self.all_exts = settings.RMT_MEDIAEXT + # 待整理任务队列 + self._queue = queue.Queue() + # 文件整理线程 + self._transfer_thread = None + # 队列间隔时间(秒) + self._transfer_interval = 15 + # 事件管理器 self.jobview = JobManager() - # 启动整理任务 self.__init() @@ -1101,7 +1098,8 @@ class TransferChain(ChainBase, metaclass=Singleton): # 自定义识别 if formaterHandler: # 开始集、结束集、PART - begin_ep, end_ep, part = formaterHandler.split_episode(file_name=file_path.name, file_meta=file_meta) + begin_ep, end_ep, part = formaterHandler.split_episode(file_name=file_path.name, + file_meta=file_meta) if begin_ep is not None: file_meta.begin_episode = begin_ep file_meta.part = part diff --git a/app/core/event.py b/app/core/event.py index a05c70d9..6eb35aa7 100644 --- a/app/core/event.py +++ b/app/core/event.py @@ -69,9 +69,6 @@ class EventManager(metaclass=Singleton): EventManager 负责管理和调度广播事件和链式事件,包括订阅、发送和处理事件 """ - # 退出事件 - __event = threading.Event() - def __init__(self): self.__executor = ThreadHelper() # 动态线程池,用于消费事件 self.__consumer_threads = [] # 用于保存启动的事件消费者线程 @@ -81,6 +78,7 @@ class EventManager(metaclass=Singleton): self.__disabled_handlers = set() # 禁用的事件处理器集合 self.__disabled_classes = set() # 禁用的事件处理器类集合 self.__lock = threading.Lock() # 线程锁 + self.__event = threading.Event() # 退出事件 def start(self): """ diff --git a/app/core/meta/customization.py b/app/core/meta/customization.py index 86c79a90..15abbba3 100644 --- a/app/core/meta/customization.py +++ b/app/core/meta/customization.py @@ -9,8 +9,6 @@ class CustomizationMatcher(metaclass=Singleton): """ 识别自定义占位符 """ - customization = None - custom_separator = None def __init__(self): self.systemconfig = SystemConfigOper() diff --git a/app/core/meta/releasegroup.py b/app/core/meta/releasegroup.py index 4545ec2a..13f0da8d 100644 --- a/app/core/meta/releasegroup.py +++ b/app/core/meta/releasegroup.py @@ -9,7 +9,6 @@ class ReleaseGroupsMatcher(metaclass=Singleton): """ 识别制作组、字幕组 """ - __release_groups: str = None # 内置组 RELEASE_GROUPS: dict = { "0ff": ['FF(?:(?:A|WE)B|CD|E(?:DU|B)|TV)'], diff --git a/app/core/module.py b/app/core/module.py index 90a906d6..45c31028 100644 --- a/app/core/module.py +++ b/app/core/module.py @@ -16,14 +16,14 @@ class ModuleManager(metaclass=Singleton): 模块管理器 """ - # 模块列表 - _modules: dict = {} - # 运行态模块列表 - _running_modules: dict = {} # 子模块类型集合 SubType = Union[DownloaderType, MediaServerType, MessageChannel, StorageSchema, OtherModulesType] def __init__(self): + # 模块列表 + self._modules: dict = {} + # 运行态模块列表 + self._running_modules: dict = {} self.load_modules() def load_modules(self): diff --git a/app/core/plugin.py b/app/core/plugin.py index 9b8beeae..c8355893 100644 --- a/app/core/plugin.py +++ b/app/core/plugin.py @@ -10,6 +10,7 @@ from concurrent.futures import ThreadPoolExecutor, as_completed from pathlib import Path from typing import Any, Dict, List, Optional, Type, Union, Callable, Tuple +from app.helper.sites import SitesHelper from fastapi import HTTPException from starlette import status from watchdog.events import FileSystemEventHandler @@ -21,7 +22,6 @@ from app.core.event import eventmanager, Event from app.db.plugindata_oper import PluginDataOper from app.db.systemconfig_oper import SystemConfigOper from app.helper.plugin import PluginHelper -from app.helper.sites import SitesHelper from app.log import logger from app.schemas.types import EventType, SystemConfigKey from app.utils.crypto import RSAUtils @@ -88,16 +88,15 @@ class PluginManager(metaclass=Singleton): 插件管理器 """ - # 插件列表 - _plugins: dict = {} - # 运行态插件列表 - _running_plugins: dict = {} - # 配置Key - _config_key: str = "plugin.%s" - # 监听器 - _observer: Observer = None - def __init__(self): + # 插件列表 + self._plugins: dict = {} + # 运行态插件列表 + self._running_plugins: dict = {} + # 配置Key + self._config_key: str = "plugin.%s" + # 监听器 + self._observer: Observer = None # 开发者模式监测插件修改 if settings.DEV or settings.PLUGIN_AUTO_RELOAD: self.__start_monitor() diff --git a/app/core/workflow.py b/app/core/workflow.py index a03d0215..87730c85 100644 --- a/app/core/workflow.py +++ b/app/core/workflow.py @@ -13,10 +13,9 @@ class WorkFlowManager(metaclass=Singleton): 工作流管理器 """ - # 所有动作定义 - _actions: Dict[str, Any] = {} - def __init__(self): + # 所有动作定义 + self._actions: Dict[str, Any] = {} self.init() def init(self): diff --git a/app/helper/display.py b/app/helper/display.py index 643bfd07..705a5bd2 100644 --- a/app/helper/display.py +++ b/app/helper/display.py @@ -8,7 +8,6 @@ import os class DisplayHelper(metaclass=Singleton): - _display: Display = None def __init__(self): if not SystemUtils.is_docker(): diff --git a/app/helper/doh.py b/app/helper/doh.py index 01e283d8..3495cd0f 100644 --- a/app/helper/doh.py +++ b/app/helper/doh.py @@ -70,6 +70,9 @@ def enable_doh(enable: bool): class DohHelper(metaclass=Singleton): + """ + DoH帮助类,用于处理DNS over HTTPS解析。 + """ def __init__(self): enable_doh(settings.DOH_ENABLE) diff --git a/app/monitor.py b/app/monitor.py index 5798805b..851b51bb 100644 --- a/app/monitor.py +++ b/app/monitor.py @@ -59,26 +59,23 @@ class Monitor(metaclass=Singleton): 目录监控处理链,单例模式 """ - # 退出事件 - _event = threading.Event() - # 监控服务 - _observers = [] - - # 定时服务 - _scheduler = None - - # 存储快照缓存目录 - _snapshot_cache_dir = None - - # 存储过照间隔(分钟) - _snapshot_interval = 5 - - # TTL缓存,10秒钟有效 - _cache = TTLCache(maxsize=1024, ttl=10) def __init__(self): super().__init__() + # 退出事件 + self._event = threading.Event() + # 监控服务 + self._observers = [] + # 定时服务 + self._scheduler = None + # 存储快照缓存目录 + self._snapshot_cache_dir = None + # 存储过照间隔(分钟) + self._snapshot_interval = 5 + # TTL缓存,10秒钟有效 + self._cache = TTLCache(maxsize=1024, ttl=10) + # 监控的文件扩展名 self.all_exts = settings.RMT_MEDIAEXT # 初始化快照缓存目录 self._snapshot_cache_dir = settings.TEMP_PATH / "snapshots" diff --git a/app/scheduler.py b/app/scheduler.py index d73bfa75..7f3d299e 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -40,20 +40,20 @@ class Scheduler(metaclass=Singleton): """ 定时任务管理 """ - # 定时服务 - _scheduler = None - # 退出事件 - _event = threading.Event() - # 锁 - _lock = threading.RLock() - # 各服务的运行状态 - _jobs = {} - # 用户认证失败次数 - _auth_count = 0 - # 用户认证失败消息发送 - _auth_message = False def __init__(self): + # 定时服务 + self._scheduler = None + # 退出事件 + self._event = threading.Event() + # 锁 + self._lock = threading.RLock() + # 各服务的运行状态 + self._jobs = {} + # 用户认证失败次数 + self._auth_count = 0 + # 用户认证失败消息发送 + self._auth_message = False self.init() @eventmanager.register(EventType.ConfigChanged) @@ -443,7 +443,7 @@ class Scheduler(metaclass=Singleton): return with self._lock: job_id = f"workflow-{workflow.id}" - service = self._jobs.pop(job_id, None) + service = self._jobs.pop(job_id, {}) if not service: return try: