@@ -111,7 +111,7 @@ def wait_until_finish(self):
111
111
def decide_filepath (self ,
112
112
album : Optional [JmAlbumDetail ],
113
113
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 ],
115
115
dir_rule_dict : Optional [dict ]
116
116
):
117
117
"""
@@ -1219,7 +1219,7 @@ def new_decide_dir(photo, ensure_exists=True) -> str:
1219
1219
1220
1220
1221
1221
class AdvancedRetryPlugin (JmOptionPlugin ):
1222
- plugin_key = 'advanced-retry '
1222
+ plugin_key = 'advanced_retry '
1223
1223
1224
1224
def __init__ (self , option : JmOption ):
1225
1225
super ().__init__ (option )
@@ -1234,15 +1234,18 @@ def invoke(self,
1234
1234
new_jm_client : Callable = self .option .new_jm_client
1235
1235
1236
1236
def hook_new_jm_client (* args , ** kwargs ):
1237
- client : JmcomicClient = new_jm_client (* args , ** kwargs )
1238
- client .domain_retry_strategy = self .request_with_retry
1239
- client .domain_req_failed_counter = {}
1240
- from threading import Lock
1241
- client .domain_counter_lock = Lock ()
1242
- return client
1237
+ return new_jm_client (* args , ** kwargs , domain_retry_strategy = self )
1243
1238
1244
1239
self .option .new_jm_client = hook_new_jm_client
1245
1240
1241
+ def __call__ (self , client : AbstractJmClient , * args , ** kwargs ):
1242
+ if args :
1243
+ return self .request_with_retry (client , * args , ** kwargs )
1244
+ # init
1245
+ from threading import Lock
1246
+ client .domain_req_failed_counter = {}
1247
+ client .domain_counter_lock = Lock ()
1248
+
1246
1249
def request_with_retry (self ,
1247
1250
client : AbstractJmClient ,
1248
1251
request : Callable ,
@@ -1306,3 +1309,25 @@ def update_failed_count(self, client: AbstractJmClient, domain: str):
1306
1309
def failed_count (client : JmcomicClient , domain : str ) -> int :
1307
1310
# noinspection PyUnresolvedReferences
1308
1311
return client .domain_req_failed_counter .get (domain , 0 )
1312
+
1313
+
1314
+ class DownloadCoverPlugin (JmOptionPlugin ):
1315
+ plugin_key = 'download_cover'
1316
+
1317
+ def invoke (self ,
1318
+ dir_rule : dict ,
1319
+ size = '' ,
1320
+ photo : JmPhotoDetail = None ,
1321
+ album : JmAlbumDetail = None ,
1322
+ downloader = None ,
1323
+ ** kwargs ) -> None :
1324
+ album_id = album .id if album else photo .album_id
1325
+ save_path = self .decide_filepath (
1326
+ album , photo ,
1327
+ None , None , None ,
1328
+ dir_rule
1329
+ )
1330
+ if self .option .download .cache and os .path .exists (save_path ):
1331
+ self .log (f'album-{ album_id } 的封面已存在,跳过下载: [{ save_path } ]' , 'skip' )
1332
+ return
1333
+ downloader .client .download_album_cover (album_id , save_path , size )
0 commit comments