From 933da4a9f9e4ed49d9b33c2a8c81fb52c076232d Mon Sep 17 00:00:00 2001 From: hect0x7 <93357912+hect0x7@users.noreply.github.com> Date: Tue, 22 Aug 2023 13:51:45 +0800 Subject: [PATCH] =?UTF-8?q?v2.1.13:=20=E5=AF=B9JmModuleConfig=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E9=85=8D=E7=BD=AE=E7=B1=BB=E4=BD=8D=E7=BD=AE=20(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jmcomic/__init__.py | 2 +- src/jmcomic/jm_config.py | 30 ++++++++++++++++++++++++------ src/jmcomic/jm_toolkit.py | 12 ++++-------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/jmcomic/__init__.py b/src/jmcomic/__init__.py index 7bd371b1..759f0ac7 100644 --- a/src/jmcomic/__init__.py +++ b/src/jmcomic/__init__.py @@ -2,6 +2,6 @@ # 被依赖方 <--- 使用方 # config <--- entity <--- toolkit <--- client <--- option <--- downloader -__version__ = '2.1.12' +__version__ = '2.1.13' from .api import * diff --git a/src/jmcomic/jm_config.py b/src/jmcomic/jm_config.py index f8e3942b..a8396c1c 100644 --- a/src/jmcomic/jm_config.py +++ b/src/jmcomic/jm_config.py @@ -52,8 +52,10 @@ class JmModuleConfig: # 模块级别的可重写配置 DOMAIN = None DOMAIN_LIST = None - DOWNLOADER_CLASS = None - OPTION_CLASS = None + CLASS_DOWNLOADER = None + CLASS_OPTION = None + CLASS_ALBUM = None + CLASS_PHOTO = None # 执行debug的函数 debug_executor = default_jm_debug @@ -64,20 +66,36 @@ class JmModuleConfig: @classmethod def downloader_class(cls): - if cls.DOWNLOADER_CLASS is not None: - return cls.DOWNLOADER_CLASS + if cls.CLASS_DOWNLOADER is not None: + return cls.CLASS_DOWNLOADER from .jm_downloader import JmDownloader return JmDownloader @classmethod def option_class(cls): - if cls.OPTION_CLASS is not None: - return cls.OPTION_CLASS + if cls.CLASS_OPTION is not None: + return cls.CLASS_OPTION from .jm_option import JmOption return JmOption + @classmethod + def album_class(cls): + if cls.CLASS_ALBUM is not None: + return cls.CLASS_ALBUM + + from .jm_entity import JmAlbumDetail + return JmAlbumDetail + + @classmethod + def photo_class(cls): + if cls.CLASS_PHOTO is not None: + return cls.CLASS_PHOTO + + from .jm_entity import JmPhotoDetail + return JmPhotoDetail + @classmethod @field_cache("DOMAIN") def domain(cls, postman=None): diff --git a/src/jmcomic/jm_toolkit.py b/src/jmcomic/jm_toolkit.py index 7ac4d5ea..dd320bce 100644 --- a/src/jmcomic/jm_toolkit.py +++ b/src/jmcomic/jm_toolkit.py @@ -88,24 +88,20 @@ def analyse_jm_pub_html(cls, html: str, domain_keyword=('jm', 'comic')) -> List[ domain_ls )) - # 可以替换下面两个类为用户自定义的、二次继承的类 - PhotoClass = JmPhotoDetail - AlbumClass = JmAlbumDetail - @classmethod - def analyse_jm_photo_html(cls, html: str) -> PhotoClass: + def analyse_jm_photo_html(cls, html: str) -> JmPhotoDetail: return cls.reflect_new_instance( html, "pattern_html_photo_", - cls.PhotoClass + JmModuleConfig.photo_class() ) @classmethod - def analyse_jm_album_html(cls, html: str) -> AlbumClass: + def analyse_jm_album_html(cls, html: str) -> JmAlbumDetail: return cls.reflect_new_instance( html, "pattern_html_album_", - cls.AlbumClass + JmModuleConfig.album_class() ) @classmethod