44def download_batch (download_api ,
55 jm_id_iter : Union [Iterable , Generator ],
66 option = None ,
7+ downloader = None ,
78 ):
89 """
910 批量下载 album / photo
@@ -12,6 +13,7 @@ def download_batch(download_api,
1213 @param download_api: 下载api
1314 @param jm_id_iter: jmid (album_id, photo_id) 的迭代器
1415 @param option: 下载选项,对所有的jmid使用同一个,默认是 JmOption.default()
16+ @param downloader: 下载器类
1517 """
1618 from common import multi_thread_launcher
1719
@@ -23,41 +25,45 @@ def download_batch(download_api,
2325 JmcomicText .parse_to_album_id (jmid )
2426 for jmid in jm_id_iter
2527 ),
26- apply_each_obj_func = lambda aid : download_api (aid , option ),
28+ apply_each_obj_func = lambda aid : download_api (aid , option , downloader ),
2729 )
2830
2931
30- def download_album (jm_album_id , option = None ):
32+ def download_album (jm_album_id , option = None , downloader = None ):
3133 """
3234 下载一个本子
3335 @param jm_album_id: 禁漫的本子的id,类型可以是str/int/iterable[str]。
3436 如果是iterable[str],则会调用 download_album_batch
3537 @param option: 下载选项,为空默认是 JmOption.default()
38+ @param downloader: 下载器类
3639 """
3740
3841 if not isinstance (jm_album_id , (str , int )):
39- return download_batch (download_album , jm_album_id , option )
42+ return download_batch (download_album , jm_album_id , option , downloader )
4043
41- with new_downloader (option ) as dler :
44+ with new_downloader (option , downloader ) as dler :
4245 dler .download_album (jm_album_id )
4346
4447
45- def download_photo (jm_photo_id , option = None ):
48+ def download_photo (jm_photo_id , option = None , downloader = None ):
4649 """
4750 下载一个章节
4851 """
4952 if not isinstance (jm_photo_id , (str , int )):
5053 return download_batch (download_photo , jm_photo_id , option )
5154
52- with new_downloader (option ) as dler :
55+ with new_downloader (option , downloader ) as dler :
5356 dler .download_photo (jm_photo_id )
5457
5558
56- def new_downloader (option = None ) :
59+ def new_downloader (option = None , downloader = None ) -> JmDownloader :
5760 if option is None :
5861 option = JmModuleConfig .option_class ().default ()
5962
60- return JmModuleConfig .downloader_class ()(option )
63+ if downloader is None :
64+ downloader = JmModuleConfig .downloader_class ()
65+
66+ return downloader (option )
6167
6268
6369def create_option (filepath ):
0 commit comments