@@ -60,10 +60,16 @@ def enable_client_cache_on_condition(cls,
6060class DirRule :
6161 RULE_BASE_DIR = 'Bd'
6262
63- def __init__ (self , rule : str , base_dir = None ):
63+ def __init__ (self , rule : str , base_dir = None , normalize_zh = None ):
64+ """
65+ :param rule: DSL rule
66+ :param base_dir: base directory
67+ :param normalize_zh: 'zh-cn'|'zh-tw'| or None. 控制是否以及如何进行繁简体归一化,默认 None
68+ """
6469 base_dir = JmcomicText .parse_to_abspath (base_dir )
6570 self .base_dir = base_dir
6671 self .rule_dsl = rule
72+ self .normalize_zh = normalize_zh
6773 self .parser_list : List [Tuple [str , Callable ]] = self .get_rule_parser_list (rule )
6874
6975 def decide_image_save_dir (self ,
@@ -88,7 +94,9 @@ def apply_rule_to_path(self, album, photo, only_album_rules=False) -> str:
8894 jm_log ('dir_rule' , f'路径规则"{ rule } "的解析出错: { e } , album={ album } , photo={ photo } ' )
8995 raise e
9096 if parser != self .parse_bd_rule :
91- path = fix_windir_name (str (path )).strip ()
97+ # 根据配置 normalize_zh 进行繁简体统一
98+ conv_path = JmcomicText .to_zh (str (path ), self .normalize_zh )
99+ path = fix_windir_name (conv_path ).strip ()
92100
93101 path_ls .append (path )
94102
@@ -201,6 +209,7 @@ def copy_option(self):
201209 dir_rule = {
202210 'rule' : self .dir_rule .rule_dsl ,
203211 'base_dir' : self .dir_rule .base_dir ,
212+ 'normalize_zh' : self .dir_rule .normalize_zh ,
204213 },
205214 download = self .download .src_dict ,
206215 client = self .client .src_dict ,
@@ -326,6 +335,7 @@ def deconstruct(self) -> Dict:
326335 'dir_rule' : {
327336 'rule' : self .dir_rule .rule_dsl ,
328337 'base_dir' : self .dir_rule .base_dir ,
338+ 'normalize_zh' : self .dir_rule .normalize_zh ,
329339 },
330340 'download' : self .download .src_dict ,
331341 'client' : self .client .src_dict ,
0 commit comments