mirror of
https://github.com/hect0x7/JMComic-Crawler-Python.git
synced 2025-09-26 22:31:30 +08:00
Compare commits
2 Commits
fc3531a402
...
205f332786
Author | SHA1 | Date | |
---|---|---|---|
![]() |
205f332786 | ||
![]() |
f9fc27eb88 |
@ -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:
|
||||
|
@ -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轮
|
||||
|
@ -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,
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user