Compare commits

...

2 Commits

Author SHA1 Message Date
hect0x7
205f332786 polish code 2025-09-21 21:25:41 +08:00
hect0x7
f9fc27eb88 v2.6.8: 增加下载本子封面的函数以及插件 2025-09-21 19:35:12 +08:00
6 changed files with 42 additions and 9 deletions

View File

@ -109,12 +109,12 @@ dir_rule:
# 规则: 根目录 / 本子id / 章节序号 / 图片文件
# rule: 'Bd / Aid / Pindex'
# rule: 'Bd_Aid_Pindex'
# 默认规则是: 根目录 / 章节标题 / 图片文件
rule: Bd_Ptitle
rule: Bd / Ptitle
# jmcomic v2.5.36 以后支持使用python的f-string的语法组合文件夹名下为示例
# rule: Bd / Aauthor / (JM{Aid}-{Pindex})-{Pname}
# {}大括号里的内容同样是写 Axxx 或 Pxxx其他语法自行参考python f-string的语法
# 另外rule开头的Bd可忽略不写因为程序会自动插入Bd
```
## 3. option插件配置项
@ -194,6 +194,15 @@ plugins:
album_photo_dict:
324930: 424507
before_album:
- plugin: download-cover # 额外下载本子封面的插件
kwargs:
size: '_3x4' # 可选项,禁漫搜索页的封面图尺寸是 4x3和详情页不一样想下搜索页的封面就设置此项
dir_rule: # 封面图存放路径规则,写法同上
base_dir: D:/a/b/c/
rule: '{Atitle}/{Aid}_cover.jpg'
after_album:
- plugin: zip # 压缩文件插件
kwargs:

View File

@ -27,7 +27,7 @@ plugins:
proxy_client_key: photo_concurrent_fetcher_proxy
whitelist: [ api, ]
- plugin: advanced-retry
- plugin: advanced_retry
kwargs:
retry_config:
retry_rounds: 3 # 一共对域名列表重试3轮

View File

@ -293,9 +293,9 @@ class JmImageClient:
# https://cdn-msp2.18comic.vip/media/photos/498976/00027.gif
return data_original.endswith('.gif')
def download_album_cover(self, album_id, save_path: str):
def download_album_cover(self, album_id, save_path: str, size: str = ''):
self.download_image(
img_url=JmcomicText.get_album_cover_url(album_id),
img_url=JmcomicText.get_album_cover_url(album_id, size=size),
img_save_path=save_path,
scramble_id=None,
decode_image=False,

View File

@ -158,7 +158,8 @@ class DirRule:
if rule.startswith(('A', 'P')):
return cls.parse_detail_rule
ExceptionTool.raises(f'不支持的rule配置: "{rule}"')
return cls.parse_f_string_rule
# ExceptionTool.raises(f'不支持的rule配置: "{rule}"')
@classmethod
def apply_rule_to_filename(cls, album, photo, rule: str) -> str:

View File

@ -111,7 +111,7 @@ class JmOptionPlugin:
def decide_filepath(self,
album: Optional[JmAlbumDetail],
photo: Optional[JmPhotoDetail],
filename_rule: str, suffix: str, base_dir: Optional[str],
filename_rule: Optional[str], suffix: Optional[str], base_dir: Optional[str],
dir_rule_dict: Optional[dict]
):
"""
@ -1219,7 +1219,7 @@ class ReplacePathStringPlugin(JmOptionPlugin):
class AdvancedRetryPlugin(JmOptionPlugin):
plugin_key = 'advanced-retry'
plugin_key = 'advanced_retry'
def __init__(self, option: JmOption):
super().__init__(option)
@ -1306,3 +1306,25 @@ class AdvancedRetryPlugin(JmOptionPlugin):
def failed_count(client: JmcomicClient, domain: str) -> int:
# noinspection PyUnresolvedReferences
return client.domain_req_failed_counter.get(domain, 0)
class DownloadCoverPlugin(JmOptionPlugin):
plugin_key = 'download_cover'
def invoke(self,
dir_rule: dict,
size='',
photo: JmPhotoDetail = None,
album: JmAlbumDetail = None,
downloader=None,
**kwargs) -> None:
album_id = album.id if album else photo.album_id
save_path = self.decide_filepath(
album, photo,
None, None, None,
dir_rule
)
if self.option.download.cache and os.path.exists(save_path):
self.log(f'album-{album_id}的封面已存在,跳过下载: [{save_path}]', 'skip')
return
downloader.client.download_album_cover(album_id, save_path, size)

View File

@ -335,4 +335,5 @@ class Test_Client(JmTestConfigurable):
def test_download_cover(self):
album_id = 123
self.client.download_album_cover(album_id, f'./{album_id}.jpg')
self.client.download_album_cover(album_id, f'{self.option.dir_rule.base_dir}/{album_id}.webp')
self.client.download_album_cover(album_id, f'{self.option.dir_rule.base_dir}/{album_id}_3x4.webp', '_3x4')