@@ -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 """
@@ -1219,7 +1219,7 @@ def new_decide_dir(photo, ensure_exists=True) -> str:
12191219
12201220
12211221class AdvancedRetryPlugin (JmOptionPlugin ):
1222- plugin_key = 'advanced-retry '
1222+ plugin_key = 'advanced_retry '
12231223
12241224 def __init__ (self , option : JmOption ):
12251225 super ().__init__ (option )
@@ -1234,15 +1234,18 @@ def invoke(self,
12341234 new_jm_client : Callable = self .option .new_jm_client
12351235
12361236 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 )
12431238
12441239 self .option .new_jm_client = hook_new_jm_client
12451240
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+
12461249 def request_with_retry (self ,
12471250 client : AbstractJmClient ,
12481251 request : Callable ,
@@ -1306,3 +1309,25 @@ def update_failed_count(self, client: AbstractJmClient, domain: str):
13061309 def failed_count (client : JmcomicClient , domain : str ) -> int :
13071310 # noinspection PyUnresolvedReferences
13081311 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