diff --git a/app/chain/__init__.py b/app/chain/__init__.py index d2b8fada..3c7c3dc9 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -6,7 +6,7 @@ from typing import Optional, Any, Tuple, List, Set, Union from ruamel.yaml import CommentedMap from app.core.context import Context -from app.core.module_manager import ModuleManager +from app.core.module import ModuleManager from app.core.context import MediaInfo, TorrentInfo from app.core.meta import MetaBase from app.log import logger diff --git a/app/chain/douban_sync.py b/app/chain/douban_sync.py index d7ae1980..79bada54 100644 --- a/app/chain/douban_sync.py +++ b/app/chain/douban_sync.py @@ -6,7 +6,7 @@ from app.chain.download import DownloadChain from app.chain.search import SearchChain from app.chain.subscribe import SubscribeChain from app.core.config import settings -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.core.context import MediaInfo from app.helper.rss import RssHelper from app.log import logger diff --git a/app/chain/identify.py b/app/chain/identify.py index 06427f87..4deb0b2d 100644 --- a/app/chain/identify.py +++ b/app/chain/identify.py @@ -1,7 +1,7 @@ from typing import Optional from app.chain import ChainBase -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.core.context import Context, MediaInfo from app.log import logger diff --git a/app/chain/search.py b/app/chain/search.py index 3eb1262d..b6139ee8 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -4,7 +4,7 @@ from app.chain import ChainBase from app.core.config import settings from app.core.context import Context, MediaInfo, TorrentInfo from app.core.meta import MetaBase -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.helper.sites import SitesHelper from app.log import logger diff --git a/app/chain/subscribe.py b/app/chain/subscribe.py index f7c0b82b..b33cd326 100644 --- a/app/chain/subscribe.py +++ b/app/chain/subscribe.py @@ -3,7 +3,7 @@ from typing import Dict, List, Optional from app.chain import ChainBase from app.chain.download import DownloadChain from app.chain.search import SearchChain -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.core.context import TorrentInfo, Context, MediaInfo from app.core.config import settings from app.db.subscribes import Subscribes diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 0c0dea8b..f870cdb9 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -1,7 +1,7 @@ from typing import List, Optional from app.chain import ChainBase -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.core.context import MediaInfo from app.core.config import settings from app.core.meta import MetaBase diff --git a/app/chain/user_message.py b/app/chain/user_message.py index c7f7140c..7fda4dd7 100644 --- a/app/chain/user_message.py +++ b/app/chain/user_message.py @@ -4,8 +4,8 @@ from app.chain.download import * from app.chain.search import SearchChain from app.chain.subscribe import SubscribeChain from app.core.context import MediaInfo, TorrentInfo -from app.core.meta_info import MetaInfo -from app.core.event_manager import EventManager +from app.core.metainfo import MetaInfo +from app.core.event import EventManager from app.log import logger from app.utils.types import EventType diff --git a/app/command.py b/app/command.py index 585ae039..17437143 100644 --- a/app/command.py +++ b/app/command.py @@ -7,9 +7,9 @@ from app.chain.cookiecloud import CookieCloudChain from app.chain.douban_sync import DoubanSyncChain from app.chain.subscribe import SubscribeChain from app.chain.transfer import TransferChain -from app.core.event_manager import eventmanager, EventManager -from app.core.plugin_manager import PluginManager -from app.core.event_manager import Event as ManagerEvent +from app.core.event import eventmanager, EventManager +from app.core.plugin import PluginManager +from app.core.event import Event as ManagerEvent from app.log import logger from app.utils.singleton import Singleton from app.utils.types import EventType diff --git a/app/core/context.py b/app/core/context.py index 52dc9c24..9f1e76b7 100644 --- a/app/core/context.py +++ b/app/core/context.py @@ -2,7 +2,7 @@ from typing import Optional, Any, List from app.core.config import settings from app.core.meta import MetaBase -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.utils.types import MediaType diff --git a/app/core/event_manager.py b/app/core/event.py similarity index 100% rename from app/core/event_manager.py rename to app/core/event.py diff --git a/app/core/meta_info.py b/app/core/metainfo.py similarity index 100% rename from app/core/meta_info.py rename to app/core/metainfo.py diff --git a/app/core/module_manager.py b/app/core/module.py similarity index 69% rename from app/core/module_manager.py rename to app/core/module.py index 1f16b9f1..901016cc 100644 --- a/app/core/module_manager.py +++ b/app/core/module.py @@ -35,9 +35,12 @@ class ModuleManager(metaclass=Singleton): module_id = module.__name__ self._modules[module_id] = module # 生成实例 - self._running_modules[module_id] = module() - self._running_modules[module_id].init_module() - logger.info(f"Moudle Loaded:{module_id}") + _module = module() + # 初始化模块 + if self.check_setting(_module.init_setting()): + _module.init_module() + self._running_modules[module_id] = _module + logger.info(f"Moudle Loaded:{module_id}") def stop(self): """ @@ -47,6 +50,20 @@ class ModuleManager(metaclass=Singleton): if hasattr(module, "stop"): module.stop() + @staticmethod + def check_setting(setting: Optional[tuple]) -> bool: + """ + 检查开关是否己打开 + """ + if not setting: + return True + switch, value = setting + if getattr(settings, switch) and value is True: + return True + if getattr(settings, switch) == value: + return True + return False + def get_modules(self, method: str) -> Generator: """ 获取模块列表 @@ -58,23 +75,9 @@ class ModuleManager(metaclass=Singleton): """ return func.__code__.co_code != b'd\x01S\x00' - def check_setting(setting: Optional[tuple]) -> bool: - """ - 检查开关是否己打开 - """ - if not setting: - return True - switch, value = setting - if getattr(settings, switch) and value is True: - return True - if getattr(settings, switch) == value: - return True - return False - if not self._running_modules: return [] for _, module in self._running_modules.items(): if hasattr(module, method) \ - and check_method(getattr(module, method)) \ - and check_setting(module.init_setting()): + and check_method(getattr(module, method)): yield module diff --git a/app/core/plugin_manager.py b/app/core/plugin.py similarity index 100% rename from app/core/plugin_manager.py rename to app/core/plugin.py diff --git a/app/helper/torrent.py b/app/helper/torrent.py index 21365da1..c91c2c33 100644 --- a/app/helper/torrent.py +++ b/app/helper/torrent.py @@ -8,7 +8,7 @@ from torrentool.api import Torrent from app.core.config import settings from app.core.context import Context -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.log import logger from app.utils.http import RequestUtils from app.utils.string import StringUtils diff --git a/app/main.py b/app/main.py index 4bbf6ce9..de89f107 100644 --- a/app/main.py +++ b/app/main.py @@ -5,8 +5,8 @@ from uvicorn import Config from app.api.apiv1 import api_router from app.command import Command from app.core.config import settings -from app.core.module_manager import ModuleManager -from app.core.plugin_manager import PluginManager +from app.core.module import ModuleManager +from app.core.plugin import PluginManager from app.db.init import init_db, update_db from app.helper.sites import SitesHelper from app.scheduler import Scheduler diff --git a/app/modules/douban/__init__.py b/app/modules/douban/__init__.py index e487e03e..aa7b5f82 100644 --- a/app/modules/douban/__init__.py +++ b/app/modules/douban/__init__.py @@ -5,7 +5,7 @@ from xml.dom import minidom from app.core.context import MediaInfo from app.core.config import settings -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.core.meta import MetaBase from app.log import logger from app.modules import _ModuleBase @@ -18,12 +18,10 @@ from app.utils.types import MediaType class Douban(_ModuleBase): - def __init__(self): - super().__init__() - self.doubanapi = DoubanApi() + doubanapi: DoubanApi = None def init_module(self) -> None: - pass + self.doubanapi = DoubanApi() def stop(self): pass diff --git a/app/modules/filetransfer/__init__.py b/app/modules/filetransfer/__init__.py index b3ccd943..453d3a31 100644 --- a/app/modules/filetransfer/__init__.py +++ b/app/modules/filetransfer/__init__.py @@ -6,7 +6,7 @@ from typing import Optional, List, Tuple, Union from jinja2 import Template from app.core.context import MediaInfo -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.core.config import settings from app.core.meta import MetaBase from app.log import logger diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 97b595b3..1f247ae1 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import Set, Tuple, Optional, Union, List from app.core.config import settings -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.modules import _ModuleBase from app.modules.qbittorrent.qbittorrent import Qbittorrent from app.utils.string import StringUtils diff --git a/app/modules/telegram/telegram.py b/app/modules/telegram/telegram.py index 8a52933a..cc431fdd 100644 --- a/app/modules/telegram/telegram.py +++ b/app/modules/telegram/telegram.py @@ -20,9 +20,6 @@ class Telegram(metaclass=Singleton): """ 初始化参数 """ - if settings.MESSAGER != "telegram": - return - # Token self._telegram_token = settings.TELEGRAM_TOKEN # Chat Id diff --git a/app/modules/themoviedb/__init__.py b/app/modules/themoviedb/__init__.py index 1deddc3d..4640f679 100644 --- a/app/modules/themoviedb/__init__.py +++ b/app/modules/themoviedb/__init__.py @@ -5,7 +5,7 @@ from xml.dom import minidom from app.core.config import settings from app.core.context import MediaInfo -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.core.meta import MetaBase from app.log import logger from app.modules import _ModuleBase diff --git a/app/modules/transmission/__init__.py b/app/modules/transmission/__init__.py index b959f573..78a16df5 100644 --- a/app/modules/transmission/__init__.py +++ b/app/modules/transmission/__init__.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import Set, Tuple, Optional, Union, List from app.core.config import settings -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from app.modules import _ModuleBase from app.modules.transmission.transmission import Transmission from app.utils.types import TorrentStatus diff --git a/app/plugins/autosignin/__init__.py b/app/plugins/autosignin/__init__.py index d21e778d..aeb00084 100644 --- a/app/plugins/autosignin/__init__.py +++ b/app/plugins/autosignin/__init__.py @@ -7,7 +7,7 @@ from urllib.parse import urljoin from apscheduler.schedulers.background import BackgroundScheduler from ruamel.yaml import CommentedMap -from app.core.event_manager import EventManager, eventmanager +from app.core.event import EventManager, eventmanager from app.core.config import settings from app.helper.browser import PlaywrightHelper from app.helper.cloudflare import under_challenge diff --git a/app/plugins/sitestatistic/__init__.py b/app/plugins/sitestatistic/__init__.py index 8348345a..9e974ab6 100644 --- a/app/plugins/sitestatistic/__init__.py +++ b/app/plugins/sitestatistic/__init__.py @@ -8,8 +8,8 @@ from apscheduler.schedulers.background import BackgroundScheduler from ruamel.yaml import CommentedMap from app.core.config import settings -from app.core.event_manager import eventmanager -from app.core.event_manager import Event +from app.core.event import eventmanager +from app.core.event import Event from app.helper.browser import PlaywrightHelper from app.helper.module import ModuleHelper from app.helper.sites import SitesHelper diff --git a/tests/test_metainfo.py b/tests/test_metainfo.py index 6132d628..8d23861e 100644 --- a/tests/test_metainfo.py +++ b/tests/test_metainfo.py @@ -2,7 +2,7 @@ from unittest import TestCase -from app.core.meta_info import MetaInfo +from app.core.metainfo import MetaInfo from tests.cases.meta import meta_cases