@@ -19,8 +19,11 @@ def download_album(jm_album_id, option=None):
1919 f'获得album_detail成功,准备下载。'
2020 f'本子作者是【{ album_detail .author } 】,一共有{ len (album_detail )} 集本子' )
2121
22- def download_photo (index , photo_detail : JmPhotoDetail , debug_topic = 'download_album_photo' ):
23- jm_client .fill_page_arr (photo_detail )
22+ def download_photo (index : int ,
23+ photo_detail : JmPhotoDetail ,
24+ debug_topic = 'download_album_photo' ,
25+ ):
26+ jm_client .update (photo_detail )
2427
2528 jm_debug (debug_topic ,
2629 f"下载第[{ index + 1 } ]集: "
@@ -37,16 +40,16 @@ def download_photo(index, photo_detail: JmPhotoDetail, debug_topic='download_alb
3740 f"下载完成:({ photo_detail .title } ) "
3841 f"-- photo { photo_detail .photo_id } " )
3942
40- multi_thread_launcher (
43+ thread_pool_executor (
4144 iter_objs = enumerate (album_detail ),
4245 apply_each_obj_func = download_photo ,
43- wait_finish = True ,
4446 )
4547
4648
4749def download_album_batch (jm_album_id_iter : Union [Iterable , Generator ],
4850 option = None ,
49- wait_finish = True ) -> List [Thread ]:
51+ wait_finish = True ,
52+ ) -> List [Thread ]:
5053 """
5154 批量下载album,每个album一个线程,使用的是同一个option。
5255
@@ -58,7 +61,7 @@ def download_album_batch(jm_album_id_iter: Union[Iterable, Generator],
5861 if option is None :
5962 option = JmOption .default ()
6063
61- return multi_thread_launcher (
64+ return thread_pool_executor (
6265 iter_objs = ((album_id , option ) for album_id in jm_album_id_iter ),
6366 apply_each_obj_func = download_album ,
6467 wait_finish = wait_finish ,
@@ -92,18 +95,17 @@ def download_by_photo_detail(photo_detail: JmPhotoDetail,
9295 jm_client .fill_from_album (photo_detail )
9396
9497 if photo_detail .page_arr is None :
95- jm_client .fill_page_arr (photo_detail )
98+ jm_client .update (photo_detail )
9699
97100 # 下载每个图片的函数
98- def download_image (index , debug_topic = 'download_images_of_photo' ):
99- img_detail = photo_detail [index ]
101+ def download_image (index ,img_detail , debug_topic = 'download_images_of_photo' ):
100102 img_save_path = option .decide_image_filepath (photo_detail , index )
101103
102104 # 已下载过,缓存命中
103105 if use_cache is True and file_exists (img_save_path ):
104106 jm_debug (debug_topic , f'photo-{ img_detail .aid } : '
105107 f'图片{ img_detail .filename } 已下载过,'
106- f'命中磁盘缓存({ img_detail . img_url } )' )
108+ f'命中磁盘缓存({ img_save_path } )' )
107109 return
108110
109111 # 开始下载
@@ -121,26 +123,15 @@ def download_image(index, debug_topic='download_images_of_photo'):
121123 if length <= option .download_multi_thread_photo_len_limit :
122124 # 如果图片数小的话,直接使用多线程下载,一张图一个线程。
123125 multi_thread_launcher (
124- iter_objs = range ( len ( photo_detail ) ),
126+ iter_objs = enumerate ( photo_detail ),
125127 apply_each_obj_func = download_image ,
126- wait_finish = True
127128 )
128129 else :
129130 # 如果图片数多的话,还是分批下载。
130- batch_count = option .download_multi_thread_photo_batch_count
131- batch_times = length // batch_count
132-
133- for i in range (batch_times ):
134- begin = i * batch_count
135- multi_thread_launcher (
136- iter_objs = range (begin , begin + batch_count ),
137- apply_each_obj_func = download_image ,
138- )
139-
140- multi_thread_launcher (
141- iter_objs = range (batch_times * batch_count ,
142- length ),
131+ multi_task_launcher_batch (
132+ iter_objs = enumerate (photo_detail ),
143133 apply_each_obj_func = download_image ,
134+ batch_size = option .download_multi_thread_photo_batch_count
144135 )
145136
146137
0 commit comments