diff --git a/app/core/module.py b/app/core/module.py index 27b9831c..c3543cff 100644 --- a/app/core/module.py +++ b/app/core/module.py @@ -1,11 +1,12 @@ import traceback -from typing import Generator, Optional, Tuple, Any +from typing import Generator, Optional, Tuple, Any, Union from app.core.config import settings from app.core.event import eventmanager from app.helper.module import ModuleHelper from app.log import logger -from app.schemas.types import EventType, ModuleType +from app.schemas.types import EventType, ModuleType, DownloaderType, MediaServerType, MessageChannel, StorageSchema, \ + OtherModulesType from app.utils.object import ObjectUtils from app.utils.singleton import Singleton @@ -19,6 +20,8 @@ class ModuleManager(metaclass=Singleton): _modules: dict = {} # 运行态模块列表 _running_modules: dict = {} + # 子模块类型集合 + SubType = Union[DownloaderType, MediaServerType, MessageChannel, StorageSchema, OtherModulesType] def __init__(self): self.load_modules() @@ -135,6 +138,17 @@ class ModuleManager(metaclass=Singleton): and module.get_type() == module_type: yield module + def get_running_subtype_module(self, module_subtype: SubType) -> Generator: + """ + 获取指定子类型的模块 + """ + if not self._running_modules: + return [] + for _, module in self._running_modules.items(): + if hasattr(module, 'get_subtype') \ + and module.get_subtype() == module_subtype: + yield module + def get_module(self, module_id: str) -> Any: """ 根据模块id获取模块 diff --git a/app/modules/indexer/__init__.py b/app/modules/indexer/__init__.py index 14c66daa..99c80d12 100644 --- a/app/modules/indexer/__init__.py +++ b/app/modules/indexer/__init__.py @@ -18,7 +18,7 @@ from app.modules.indexer.spider.tnode import TNodeSpider from app.modules.indexer.spider.torrentleech import TorrentLeech from app.modules.indexer.spider.yema import YemaSpider from app.schemas import SiteUserData -from app.schemas.types import MediaType, ModuleType +from app.schemas.types import MediaType, ModuleType, OtherModulesType from app.utils.string import StringUtils @@ -47,6 +47,13 @@ class IndexerModule(_ModuleBase): """ return ModuleType.Indexer + @staticmethod + def get_subtype() -> OtherModulesType: + """ + 获取模块子类型 + """ + return OtherModulesType.Indexer + @staticmethod def get_priority() -> int: """ diff --git a/app/schemas/types.py b/app/schemas/types.py index aa192e98..3cb1d72c 100644 --- a/app/schemas/types.py +++ b/app/schemas/types.py @@ -220,6 +220,8 @@ class OtherModulesType(Enum): FileManager = "文件整理" # 过滤器 Filter = "过滤器" + # 站点索引 + Indexer = "站点索引" # 用户配置Key字典