@@ -17,7 +17,7 @@ def download_album(jm_album_id, option=None):
1717
1818 option .before_album (album )
1919 execute_by_condition (
20- iter_obj = album ,
20+ iter_objs = album ,
2121 apply = lambda photo : download_by_photo_detail (photo , option ),
2222 count_batch = option .decide_photo_batch_count (album )
2323 )
@@ -49,13 +49,11 @@ def download_by_photo_detail(photo: JmPhotoDetail, option=None):
4949 # 下载每个图片的函数
5050 def download_image (image : JmImageDetail ):
5151 img_save_path = option .decide_image_filepath (image )
52-
53- # 已下载过,缓存命中
54- if use_cache is True and file_exists (img_save_path ):
55- image .is_exists = True
56- return
52+ image .is_exists = file_exists (img_save_path )
5753
5854 option .before_image (image , img_save_path )
55+ if use_cache is True and image .is_exists :
56+ return
5957 jm_client .download_by_image_detail (
6058 image ,
6159 img_save_path ,
@@ -65,7 +63,7 @@ def download_image(image: JmImageDetail):
6563
6664 option .before_photo (photo )
6765 execute_by_condition (
68- iter_obj = photo ,
66+ iter_objs = photo ,
6967 apply = download_image ,
7068 count_batch = option .decide_image_batch_count (photo )
7169 )
@@ -88,28 +86,28 @@ def download_album_batch(jm_album_id_iter: Union[Iterable, Generator],
8886 option = JmOption .default ()
8987
9088 return thread_pool_executor (
91- iter_objs = ( (album_id , option ) for album_id in jm_album_id_iter ),
92- apply_each_obj_func = download_album ,
89+ iter_objs = set ( JmcomicText . parse_to_album_id (album_id ) for album_id in jm_album_id_iter ),
90+ apply_each_obj_func = lambda album_id : download_album ( album_id , option ) ,
9391 wait_finish = wait_finish ,
9492 )
9593
9694
97- def execute_by_condition (iter_obj , apply : Callable , count_batch : int ):
95+ def execute_by_condition (iter_objs , apply : Callable , count_batch : int ):
9896 """
9997 章节/图片的下载调度逻辑
10098 """
101- count_real = len (iter_obj )
99+ count_real = len (iter_objs )
102100
103101 if count_batch >= count_real :
104- # 一图一线程
102+ # 一个图/章节 对应 一个线程
105103 multi_thread_launcher (
106- iter_objs = iter_obj ,
104+ iter_objs = iter_objs ,
107105 apply_each_obj_func = apply ,
108106 )
109107 else :
110- # 创建batch个线程的线程池,当图片数>batch时要等待。
108+ # 创建batch个线程的线程池
111109 thread_pool_executor (
112- iter_objs = iter_obj ,
110+ iter_objs = iter_objs ,
113111 apply_each_obj_func = apply ,
114112 max_workers = count_batch ,
115113 )
0 commit comments