Skip to content

Commit f9fc27e

Browse files
committed
v2.6.8: 增加下载本子封面的函数以及插件
1 parent fc3531a commit f9fc27e

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

assets/docs/sources/option_file_syntax.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ dir_rule:
109109
# 规则: 根目录 / 本子id / 章节序号 / 图片文件
110110
# rule: 'Bd / Aid / Pindex'
111111
# rule: 'Bd_Aid_Pindex'
112-
113112
# 默认规则是: 根目录 / 章节标题 / 图片文件
114-
rule: Bd_Ptitle
113+
rule: Bd / Ptitle
115114
# jmcomic v2.5.36 以后,支持使用python的f-string的语法组合文件夹名,下为示例
116115
# rule: Bd / Aauthor / (JM{Aid}-{Pindex})-{Pname}
117116
# {}大括号里的内容同样是写 Axxx 或 Pxxx,其他语法自行参考python f-string的语法
117+
# 另外,rule开头的Bd可忽略不写,因为程序会自动插入Bd
118118
```
119119

120120
## 3. option插件配置项
@@ -194,6 +194,15 @@ plugins:
194194
album_photo_dict:
195195
324930: 424507
196196

197+
before_album:
198+
- plugin: download-cover # 额外下载本子封面的插件
199+
kwargs:
200+
size: '_3x4' # 可选项,禁漫搜索页的封面图尺寸是 4x3,和详情页不一样,想下搜索页的封面就设置此项
201+
dir_rule: # 封面图存放路径规则,写法同上
202+
base_dir: D:/a/b/c/
203+
rule: '{Atitle}/{Aid}_cover.jpg'
204+
205+
197206
after_album:
198207
- plugin: zip # 压缩文件插件
199208
kwargs:

src/jmcomic/jm_client_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ def img_is_not_need_to_decode(cls, data_original: str, _resp) -> bool:
293293
# https://cdn-msp2.18comic.vip/media/photos/498976/00027.gif
294294
return data_original.endswith('.gif')
295295

296-
def download_album_cover(self, album_id, save_path: str):
296+
def download_album_cover(self, album_id, save_path: str, size: str = ''):
297297
self.download_image(
298-
img_url=JmcomicText.get_album_cover_url(album_id),
298+
img_url=JmcomicText.get_album_cover_url(album_id, size=size),
299299
img_save_path=save_path,
300300
scramble_id=None,
301301
decode_image=False,

src/jmcomic/jm_option.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def get_rule_parser(cls, rule: str):
158158
if rule.startswith(('A', 'P')):
159159
return cls.parse_detail_rule
160160

161-
ExceptionTool.raises(f'不支持的rule配置: "{rule}"')
161+
return cls.parse_f_string_rule
162+
# ExceptionTool.raises(f'不支持的rule配置: "{rule}"')
162163

163164
@classmethod
164165
def apply_rule_to_filename(cls, album, photo, rule: str) -> str:

src/jmcomic/jm_plugin.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def wait_until_finish(self):
111111
def decide_filepath(self,
112112
album: Optional[JmAlbumDetail],
113113
photo: Optional[JmPhotoDetail],
114-
filename_rule: str, suffix: str, base_dir: Optional[str],
114+
filename_rule: Optional[str], suffix: Optional[str], base_dir: Optional[str],
115115
dir_rule_dict: Optional[dict]
116116
):
117117
"""
@@ -1306,3 +1306,22 @@ def update_failed_count(self, client: AbstractJmClient, domain: str):
13061306
def failed_count(client: JmcomicClient, domain: str) -> int:
13071307
# noinspection PyUnresolvedReferences
13081308
return client.domain_req_failed_counter.get(domain, 0)
1309+
1310+
1311+
class DownloadCoverPlugin(JmOptionPlugin):
1312+
plugin_key = 'download-cover'
1313+
1314+
def invoke(self,
1315+
dir_rule: dict,
1316+
size='',
1317+
photo: JmPhotoDetail = None,
1318+
album: JmAlbumDetail = None,
1319+
downloader=None,
1320+
**kwargs) -> None:
1321+
album_id = album.id if album else photo.album_id
1322+
save_path = self.decide_filepath(
1323+
album, photo,
1324+
None, None, None,
1325+
dir_rule
1326+
)
1327+
downloader.client.download_album_cover(album_id, save_path, size)

tests/test_jmcomic/test_jm_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,5 @@ def print_page(page):
335335

336336
def test_download_cover(self):
337337
album_id = 123
338-
self.client.download_album_cover(album_id, f'./{album_id}.jpg')
338+
self.client.download_album_cover(album_id, f'{self.option.dir_rule.base_dir}/{album_id}.webp')
339+
self.client.download_album_cover(album_id, f'{self.option.dir_rule.base_dir}/{album_id}_3x4.webp', '_3x4')

0 commit comments

Comments
 (0)