Skip to content

Commit e6df292

Browse files
authored
v2.0.5: 更新禁漫的发布页地址,优化代码 (#59)
1 parent 1b38daf commit e6df292

File tree

9 files changed

+19
-111
lines changed

9 files changed

+19
-111
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v3
1313

14-
- name: Set up Python 3.7
14+
- name: Set up Python 3.11
1515
uses: actions/setup-python@v4
1616
with:
17-
python-version: "3.7"
17+
python-version: "3.11"
1818

1919
- name: 构建模块
2020
run: |

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
44

5-
__version__ = '2.0.4'
5+
__version__ = '2.0.5'
66

77
from .api import *

src/jmcomic/jm_client_impl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def get_album_detail(self, album_id) -> JmAlbumDetail:
113113
# 用 JmcomicText 解析 html,返回实体类
114114
return JmcomicText.analyse_jm_album_html(resp.text)
115115

116-
def get_photo_detail(self, photo_id: str, album=True) -> JmPhotoDetail:
116+
def get_photo_detail(self, photo_id, fetch_album=True) -> JmPhotoDetail:
117117
# 参数校验
118118
photo_id = JmcomicText.parse_to_photo_id(photo_id)
119119

@@ -124,7 +124,7 @@ def get_photo_detail(self, photo_id: str, album=True) -> JmPhotoDetail:
124124
photo_detail = JmcomicText.analyse_jm_photo_html(resp.text)
125125

126126
# 一并获取该章节的所处本子
127-
if album is True:
127+
if fetch_album is True:
128128
photo_detail.from_album = self.get_album_detail(photo_detail.album_id)
129129

130130
return photo_detail

src/jmcomic/jm_client_interface.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class JmDetailClient:
127127
def get_album_detail(self, album_id) -> JmAlbumDetail:
128128
raise NotImplementedError
129129

130-
def get_photo_detail(self, photo_id: str, album=True) -> JmPhotoDetail:
130+
def get_photo_detail(self, photo_id, fetch_album=True) -> JmPhotoDetail:
131131
raise NotImplementedError
132132

133133
def ensure_photo_can_use(self, photo_detail: JmPhotoDetail):
@@ -210,4 +210,8 @@ class JmcomicClient(
210210
JmUserClient,
211211
Postman,
212212
):
213-
pass
213+
def get_jmcomic_url(self, postman=None):
214+
return JmModuleConfig.get_jmcomic_url(postman or self)
215+
216+
def get_jmcomic_domain_all(self, postman=None):
217+
return JmModuleConfig.get_jmcomic_domain_all(postman or self)

src/jmcomic/jm_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class JmModuleConfig:
88
PROT = "https://"
99
DOMAIN = None
1010
JM_REDIRECT_URL = f'{PROT}jm365.xyz/3YeBdF' # 永久網域,怕走失的小伙伴收藏起来
11-
JM_PUB_URL = f'{PROT}jmcomic1.bet'
11+
JM_PUB_URL = f'{PROT}jmcomic2.bet'
1212
JM_CDN_IMAGE_URL_TEMPLATE = PROT + 'cdn-msp.{domain}/media/photos/{photo_id}/{index:05}{suffix}' # index 从1开始
1313
JM_IMAGE_SUFFIX = ['.jpg', '.webp', '.png', '.gif']
1414

@@ -92,7 +92,7 @@ def get_jmcomic_url(cls, postman=None):
9292
"""
9393
if postman is None:
9494
from common import Postmans
95-
postman = Postmans.get_impl_clazz('cffi_Session').create()
95+
postman = Postmans.new_session()
9696

9797
resp = postman.get(cls.JM_REDIRECT_URL)
9898
url = resp.url

src/jmcomic/jm_entity.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ def id(self):
204204
def __len__(self):
205205
return len(self.page_arr)
206206

207+
def __iter__(self) -> Generator[JmImageDetail, Any, None]:
208+
return super().__iter__()
209+
207210

208211
class JmAlbumDetail(WorkEntity):
209212

@@ -297,6 +300,9 @@ def not_exist(episode):
297300

298301
return ret
299302

303+
def __iter__(self) -> Generator[JmPhotoDetail, Any, None]:
304+
return super().__iter__()
305+
300306

301307
class JmSearchPage(IterableEntity):
302308

src/jmcomic/jm_option.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,6 @@
11
from .jm_client_impl import *
22

33

4-
class JmOptionAdvice:
5-
6-
def decide_image_save_dir(self,
7-
option: 'JmOption',
8-
photo_detail: JmPhotoDetail,
9-
) -> StrNone:
10-
"""
11-
决定一个本子图片的下载文件夹
12-
@param option: JmOption对象
13-
@param photo_detail: 本子章节实体类
14-
@return: 下载文件夹,为空表示不处理
15-
"""
16-
pass
17-
18-
def decide_image_filepath(self,
19-
option: 'JmOption',
20-
photo_detail: JmPhotoDetail,
21-
index: int,
22-
) -> StrNone:
23-
"""
24-
决定一个本子图片的绝对路径
25-
@param option: JmOption对象
26-
@param photo_detail: 本子章节实体类
27-
@param index: 本子章节里的第几章图片
28-
@return: 下载绝对路径,为空表示不处理
29-
"""
30-
pass
31-
32-
def decide_image_suffix(self,
33-
option: 'JmOption',
34-
img_detail: JmImageDetail,
35-
) -> StrNone:
36-
"""
37-
决定一个图片的保存后缀名
38-
@param option: JmOption对象
39-
@param img_detail: 禁漫图片实体类
40-
@return: 保存后缀名,为空表示不处理
41-
"""
42-
pass
43-
44-
45-
class JmAdviceRegistry:
46-
advice_registration: Dict[Any, List[JmOptionAdvice]] = {}
47-
48-
@classmethod
49-
def register_advice(cls, base, *advice):
50-
advice_ls = cls.advice_registration.get(base, None)
51-
52-
if advice_ls is None:
53-
advice_ls = list(advice)
54-
cls.advice_registration[base] = advice_ls
55-
else:
56-
for e in advice:
57-
advice_ls.append(e)
58-
59-
return advice
60-
61-
@classmethod
62-
def get_advice(cls, base) -> List[JmOptionAdvice]:
63-
return cls.advice_registration.setdefault(base, [])
64-
65-
664
class DirRule:
675
rule_sample = [
686
# 根目录 / Album-id / Photo-序号 /
@@ -205,12 +143,6 @@ def download_image_suffix(self):
205143
"""
206144

207145
def decide_image_save_dir(self, photo_detail) -> str:
208-
# 先检查advice的回调,如果回调支持,则优先使用回调
209-
for advice in JmAdviceRegistry.get_advice(self):
210-
save_dir = advice.decide_image_save_dir(self, photo_detail)
211-
if save_dir is not None:
212-
return save_dir
213-
214146
# 使用 self.dir_rule 决定 save_dir
215147
save_dir = self.dir_rule.deside_image_save_dir(
216148
photo_detail.from_album,
@@ -221,12 +153,6 @@ def decide_image_save_dir(self, photo_detail) -> str:
221153
return save_dir
222154

223155
def decide_image_suffix(self, img_detail: JmImageDetail):
224-
# 先检查advice的回调,如果回调支持,则优先使用回调
225-
for advice in JmAdviceRegistry.get_advice(self):
226-
suffix = advice.decide_image_suffix(self, img_detail)
227-
if suffix is not None:
228-
return suffix
229-
230156
# 动图则使用原后缀
231157
suffix = img_detail.img_file_suffix
232158
if suffix.endswith("gif"):
@@ -236,25 +162,12 @@ def decide_image_suffix(self, img_detail: JmImageDetail):
236162
return self.download_image_suffix or suffix
237163

238164
def decide_image_filepath(self, photo_detail: JmPhotoDetail, index: int) -> str:
239-
# 先检查advice的回调,如果回调支持,则优先使用回调
240-
for advice in JmAdviceRegistry.get_advice(self):
241-
filepath = advice.decide_image_filepath(self, photo_detail, index)
242-
if filepath is not None:
243-
return filepath
244-
245165
# 通过拼接生成绝对路径
246166
save_dir = self.decide_image_save_dir(photo_detail)
247167
image: JmImageDetail = photo_detail[index]
248168
suffix = self.decide_image_suffix(image)
249169
return save_dir + image.img_file_name + suffix
250170

251-
"""
252-
下面是对Advice的支持
253-
"""
254-
255-
def register_advice(self, *advice):
256-
JmAdviceRegistry.register_advice(self, *advice)
257-
258171
"""
259172
下面是创建对象相关方法
260173
"""

src/jmcomic/jm_toolkit.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from PIL import Image
2-
31
from .jm_entity import *
42

53

tests/test_jmcomic/test_jm_api.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,6 @@ def test_batch(self):
4848
ret2 = jmcomic.download_album_batch((e for e in album_ls), self.option)
4949
self.assertEqual(len(ret2), len(album_ls), 'Generator')
5050

51-
def test_jm_option_advice(self):
52-
class MyAdvice(JmOptionAdvice):
53-
def decide_image_filepath(self,
54-
option: 'JmOption',
55-
photo_detail: JmPhotoDetail,
56-
index: int,
57-
) -> StrNone:
58-
return workspace(f'advice_{photo_detail[index].img_file_name}.test.png')
59-
60-
option = self.option
61-
option.register_advice(MyAdvice())
62-
jmcomic.download_album('366867', option)
63-
6451
def test_photo_sort(self):
6552
client = self.option.build_jm_client()
6653

0 commit comments

Comments
 (0)