Skip to content

Commit 933da4a

Browse files
authored
v2.1.13: 对JmModuleConfig统一配置类位置 (#98)
1 parent fc51940 commit 933da4a

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/jmcomic/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# 被依赖方 <--- 使用方
33
# config <--- entity <--- toolkit <--- client <--- option <--- downloader
44

5-
__version__ = '2.1.12'
5+
__version__ = '2.1.13'
66

77
from .api import *

src/jmcomic/jm_config.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ class JmModuleConfig:
5252
# 模块级别的可重写配置
5353
DOMAIN = None
5454
DOMAIN_LIST = None
55-
DOWNLOADER_CLASS = None
56-
OPTION_CLASS = None
55+
CLASS_DOWNLOADER = None
56+
CLASS_OPTION = None
57+
CLASS_ALBUM = None
58+
CLASS_PHOTO = None
5759

5860
# 执行debug的函数
5961
debug_executor = default_jm_debug
@@ -64,20 +66,36 @@ class JmModuleConfig:
6466

6567
@classmethod
6668
def downloader_class(cls):
67-
if cls.DOWNLOADER_CLASS is not None:
68-
return cls.DOWNLOADER_CLASS
69+
if cls.CLASS_DOWNLOADER is not None:
70+
return cls.CLASS_DOWNLOADER
6971

7072
from .jm_downloader import JmDownloader
7173
return JmDownloader
7274

7375
@classmethod
7476
def option_class(cls):
75-
if cls.OPTION_CLASS is not None:
76-
return cls.OPTION_CLASS
77+
if cls.CLASS_OPTION is not None:
78+
return cls.CLASS_OPTION
7779

7880
from .jm_option import JmOption
7981
return JmOption
8082

83+
@classmethod
84+
def album_class(cls):
85+
if cls.CLASS_ALBUM is not None:
86+
return cls.CLASS_ALBUM
87+
88+
from .jm_entity import JmAlbumDetail
89+
return JmAlbumDetail
90+
91+
@classmethod
92+
def photo_class(cls):
93+
if cls.CLASS_PHOTO is not None:
94+
return cls.CLASS_PHOTO
95+
96+
from .jm_entity import JmPhotoDetail
97+
return JmPhotoDetail
98+
8199
@classmethod
82100
@field_cache("DOMAIN")
83101
def domain(cls, postman=None):

src/jmcomic/jm_toolkit.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,20 @@ def analyse_jm_pub_html(cls, html: str, domain_keyword=('jm', 'comic')) -> List[
8888
domain_ls
8989
))
9090

91-
# 可以替换下面两个类为用户自定义的、二次继承的类
92-
PhotoClass = JmPhotoDetail
93-
AlbumClass = JmAlbumDetail
94-
9591
@classmethod
96-
def analyse_jm_photo_html(cls, html: str) -> PhotoClass:
92+
def analyse_jm_photo_html(cls, html: str) -> JmPhotoDetail:
9793
return cls.reflect_new_instance(
9894
html,
9995
"pattern_html_photo_",
100-
cls.PhotoClass
96+
JmModuleConfig.photo_class()
10197
)
10298

10399
@classmethod
104-
def analyse_jm_album_html(cls, html: str) -> AlbumClass:
100+
def analyse_jm_album_html(cls, html: str) -> JmAlbumDetail:
105101
return cls.reflect_new_instance(
106102
html,
107103
"pattern_html_album_",
108-
cls.AlbumClass
104+
JmModuleConfig.album_class()
109105
)
110106

111107
@classmethod

0 commit comments

Comments
 (0)