@@ -12,7 +12,7 @@ class JmcomicText:
1212 pattern_html_photo_title = compile ('<title>(.*?)\|.*</title>' )
1313 # pattern_html_photo_data_original_list = compile('data-original="(.*?)" id="album_photo_.+?"')
1414 pattern_html_photo_data_original_domain = compile ('src="https://(.*?)/media/albums/blank' )
15- pattern_html_photo_data_original_0 = compile ('data-original="(.*?)" id="album_photo' )
15+ pattern_html_photo_data_original_0 = compile ('data-original="(.*?)"[ \n ]*? id="album_photo' )
1616 pattern_html_photo_keywords = compile ('<meta name="keywords"[\s\S]*?content="(.*?)"' )
1717 pattern_html_photo_series_id = compile ('var series_id = (\d+);' )
1818 pattern_html_photo_sort = compile ('var sort = (\d+);' )
@@ -207,41 +207,33 @@ class JmImageSupport:
207207 @classmethod
208208 def save_resp_img (cls , resp : Any , filepath : str , need_convert = True ):
209209 """
210- 保存图片的响应数据
211- @param resp: Response对象
212- @param filepath: 响应数据保存的绝对路径
213- @param need_convert: True 使用PIL打开图片再保存; False 直接保存resp.content;
214- 如果需要改变图片的格式,比如 .jpg → .png,则需要neet_convert=True。
215- 如果不需要改变文件的格式,使用need_convert=False可以跳过PIL解析图片,效率更高。
210+ 接收HTTP响应对象,将其保存到图片文件.
211+ 如果需要改变图片的文件格式,比如 .jpg → .png,则需要指定参数 neet_convert=True.
212+ 如果不需要改变图片的文件格式,使用 need_convert=False,可以跳过PIL解析图片,效率更高.
213+
214+ @param resp: HTTP响应对象
215+ @param filepath: 图片文件路径
216+ @param need_convert: 是否转换图片
216217 """
217- if need_convert is True :
218- cls .save_image ( cls . open_Image ( resp . content ) , filepath )
218+ if need_convert is False :
219+ cls .save_directly ( resp , filepath )
219220 else :
220- save_resp_content ( resp , filepath )
221+ cls . save_image ( cls . open_Image ( resp . content ) , filepath )
221222
222223 @classmethod
223- def save_resp_decoded_img (cls ,
224- resp : Any ,
225- image : JmImageDetail ,
226- filepath : str
227- ) -> None :
228- cls .decode_and_save (
229- cls .get_num_by_detail (image ),
230- cls .open_Image (resp .content ),
231- filepath
232- )
224+ def save_image (cls , image : Image , filepath : str ):
225+ """
226+ 保存图片
227+
228+ @param image: PIL.Image对象
229+ @param filepath: 保存文件路径
230+ """
231+ image .save (filepath )
233232
234233 @classmethod
235- def decode_disk_img (cls ,
236- image : JmImageDetail ,
237- img_filepath : str ,
238- decoded_save_path : str
239- ) -> None :
240- cls .decode_and_save (
241- cls .get_num_by_detail (image ),
242- cls .open_Image (img_filepath ),
243- decoded_save_path
244- )
234+ def save_directly (cls , resp , filepath ):
235+ from common import save_resp_content
236+ save_resp_content (resp , filepath )
245237
246238 @classmethod
247239 def decode_and_save (cls ,
@@ -292,10 +284,6 @@ def open_Image(cls, fp: Union[str, bytes]):
292284 fp = fp if isinstance (fp , str ) else BytesIO (fp )
293285 return Image .open (fp )
294286
295- @classmethod
296- def save_image (cls , image : Image , filepath : str ):
297- image .save (filepath )
298-
299287 @classmethod
300288 def get_num (cls , scramble_id , aid , filename : str ) -> int :
301289 """
0 commit comments