Skip to content

Commit

Permalink
v2.1.13: 对JmModuleConfig统一配置类位置 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
hect0x7 authored Aug 22, 2023
1 parent fc51940 commit 933da4a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/jmcomic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# 被依赖方 <--- 使用方
# config <--- entity <--- toolkit <--- client <--- option <--- downloader

__version__ = '2.1.12'
__version__ = '2.1.13'

from .api import *
30 changes: 24 additions & 6 deletions src/jmcomic/jm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
12 changes: 4 additions & 8 deletions src/jmcomic/jm_toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 933da4a

Please sign in to comment.