11from .jm_client_impl import *
22
33
4- class JmOptionAdvice :
5-
6- def decide_image_save_dir (self ,
7- option : 'JmOption' ,
8- photo_detail : JmPhotoDetail ,
9- ) -> StrNone :
10- """
11- 决定一个本子图片的下载文件夹
12- @param option: JmOption对象
13- @param photo_detail: 本子章节实体类
14- @return: 下载文件夹,为空表示不处理
15- """
16- pass
17-
18- def decide_image_filepath (self ,
19- option : 'JmOption' ,
20- photo_detail : JmPhotoDetail ,
21- index : int ,
22- ) -> StrNone :
23- """
24- 决定一个本子图片的绝对路径
25- @param option: JmOption对象
26- @param photo_detail: 本子章节实体类
27- @param index: 本子章节里的第几章图片
28- @return: 下载绝对路径,为空表示不处理
29- """
30- pass
31-
32- def decide_image_suffix (self ,
33- option : 'JmOption' ,
34- img_detail : JmImageDetail ,
35- ) -> StrNone :
36- """
37- 决定一个图片的保存后缀名
38- @param option: JmOption对象
39- @param img_detail: 禁漫图片实体类
40- @return: 保存后缀名,为空表示不处理
41- """
42- pass
43-
44-
45- class JmAdviceRegistry :
46- advice_registration : Dict [Any , List [JmOptionAdvice ]] = {}
47-
48- @classmethod
49- def register_advice (cls , base , * advice ):
50- advice_ls = cls .advice_registration .get (base , None )
51-
52- if advice_ls is None :
53- advice_ls = list (advice )
54- cls .advice_registration [base ] = advice_ls
55- else :
56- for e in advice :
57- advice_ls .append (e )
58-
59- return advice
60-
61- @classmethod
62- def get_advice (cls , base ) -> List [JmOptionAdvice ]:
63- return cls .advice_registration .setdefault (base , [])
64-
65-
664class DirRule :
675 rule_sample = [
686 # 根目录 / Album-id / Photo-序号 /
@@ -205,12 +143,6 @@ def download_image_suffix(self):
205143 """
206144
207145 def decide_image_save_dir (self , photo_detail ) -> str :
208- # 先检查advice的回调,如果回调支持,则优先使用回调
209- for advice in JmAdviceRegistry .get_advice (self ):
210- save_dir = advice .decide_image_save_dir (self , photo_detail )
211- if save_dir is not None :
212- return save_dir
213-
214146 # 使用 self.dir_rule 决定 save_dir
215147 save_dir = self .dir_rule .deside_image_save_dir (
216148 photo_detail .from_album ,
@@ -221,12 +153,6 @@ def decide_image_save_dir(self, photo_detail) -> str:
221153 return save_dir
222154
223155 def decide_image_suffix (self , img_detail : JmImageDetail ):
224- # 先检查advice的回调,如果回调支持,则优先使用回调
225- for advice in JmAdviceRegistry .get_advice (self ):
226- suffix = advice .decide_image_suffix (self , img_detail )
227- if suffix is not None :
228- return suffix
229-
230156 # 动图则使用原后缀
231157 suffix = img_detail .img_file_suffix
232158 if suffix .endswith ("gif" ):
@@ -236,25 +162,12 @@ def decide_image_suffix(self, img_detail: JmImageDetail):
236162 return self .download_image_suffix or suffix
237163
238164 def decide_image_filepath (self , photo_detail : JmPhotoDetail , index : int ) -> str :
239- # 先检查advice的回调,如果回调支持,则优先使用回调
240- for advice in JmAdviceRegistry .get_advice (self ):
241- filepath = advice .decide_image_filepath (self , photo_detail , index )
242- if filepath is not None :
243- return filepath
244-
245165 # 通过拼接生成绝对路径
246166 save_dir = self .decide_image_save_dir (photo_detail )
247167 image : JmImageDetail = photo_detail [index ]
248168 suffix = self .decide_image_suffix (image )
249169 return save_dir + image .img_file_name + suffix
250170
251- """
252- 下面是对Advice的支持
253- """
254-
255- def register_advice (self , * advice ):
256- JmAdviceRegistry .register_advice (self , * advice )
257-
258171 """
259172 下面是创建对象相关方法
260173 """
0 commit comments