@@ -36,7 +36,7 @@ def build(cls, option: JmOption) -> 'JmOptionPlugin':
3636 return cls (option )
3737
3838 def log (self , msg , topic = None ):
39- if self .log_enable is not True :
39+ if self .log_enable :
4040 return
4141
4242 jm_log (
@@ -68,7 +68,7 @@ def execute_deletion(self, paths: List[str]):
6868 删除文件和文件夹
6969 :param paths: 路径列表
7070 """
71- if self .delete_original_file is not True :
71+ if not self .delete_original_file :
7272 return
7373
7474 for p in paths :
@@ -120,7 +120,11 @@ def decide_filepath(self,
120120 参数 dir_rule_dict 优先级最高,
121121 如果 dir_rule_dict 不为空,优先用 dir_rule_dict
122122 否则使用 base_dir + filename_rule + suffix
123+
124+ 当album为空时,自动复制为photo.from_album,防止底层dir_rule的dsl包含Axx报错
123125 """
126+ if album is None :
127+ album = photo .from_album
124128 filepath : str
125129 base_dir : str
126130 if dir_rule_dict is not None :
@@ -248,7 +252,7 @@ def warning():
248252 ])
249253 self .log (msg , topic = 'log' )
250254
251- if enable_warning is True :
255+ if enable_warning :
252256 # 警告
253257 warning ()
254258
@@ -776,7 +780,10 @@ def invoke(self,
776780 pdf_filepath = self .decide_filepath (album , photo , filename_rule , 'pdf' , pdf_dir , dir_rule )
777781
778782 # 调用 img2pdf 把 photo_dir 下的所有图片转为pdf
779- img_path_ls , img_dir_ls = self .write_img_2_pdf (pdf_filepath , album , photo , encrypt )
783+ result = self .write_img_2_pdf (pdf_filepath , album , photo , encrypt )
784+ if not result :
785+ return
786+ img_path_ls , img_dir_ls = result
780787 self .log (f'Convert Successfully: JM{ album or photo } → { pdf_filepath } ' )
781788
782789 # 执行删除
@@ -801,6 +808,7 @@ def write_img_2_pdf(self, pdf_filepath, album: JmAlbumDetail, photo: JmPhotoDeta
801808
802809 if len (img_path_ls ) == 0 :
803810 self .log (f'所有文件夹都不存在图片,无法生成pdf:{ img_dir_ls } ' , 'error' )
811+ return
804812
805813 with open (pdf_filepath , 'wb' ) as f :
806814 f .write (img2pdf .convert (img_path_ls ))
@@ -851,12 +859,14 @@ def invoke(self,
851859
852860 # 调用 PIL 把 photo_dir 下的所有图片合并为长图
853861 img_path_ls = self .write_img_2_long_img (long_img_path , album , photo )
862+ if not img_path_ls :
863+ return
854864 self .log (f'Convert Successfully: JM{ album or photo } → { long_img_path } ' )
855865
856866 # 执行删除
857867 self .execute_deletion (img_path_ls )
858868
859- def write_img_2_long_img (self , long_img_path , album : JmAlbumDetail , photo : JmPhotoDetail ) -> List [str ]:
869+ def write_img_2_long_img (self , long_img_path , album : JmAlbumDetail , photo : JmPhotoDetail ) -> Optional [ List [str ] ]:
860870 import itertools
861871 from PIL import Image
862872
@@ -868,6 +878,10 @@ def write_img_2_long_img(self, long_img_path, album: JmAlbumDetail, photo: JmPho
868878 img_paths = itertools .chain (* map (files_of_dir , img_dir_items ))
869879 img_paths = list (filter (lambda x : not x .startswith ('.' ), img_paths )) # 过滤系统文件
870880
881+ if not img_paths :
882+ self .log (f'所有文件夹都不存在图片,无法生成long_img:{ img_paths } ' , 'error' )
883+ return
884+
871885 images = self .open_images (img_paths )
872886
873887 try :
@@ -954,11 +968,11 @@ def invoke(self,
954968 base_run_kwargs .update (run )
955969 run = base_run_kwargs
956970
957- if self .running is True :
971+ if self .running :
958972 return
959973
960974 with self .run_server_lock :
961- if self .running is True :
975+ if self .running :
962976 return
963977
964978 # 服务器的代码位于一个独立库:plugin_jm_server,需要独立安装
@@ -1074,7 +1088,7 @@ def invoke(self,
10741088 self .log ('Exception happened: ' + str (e ), 'check_update.error' )
10751089 continue
10761090
1077- if has_update is False :
1091+ if not has_update :
10781092 continue
10791093
10801094 self .log (f'album={ album_id } ,发现新章节: { photo_new_list } ,准备开始下载' )
0 commit comments