fix: 统一数据格式 & 处理无效正则

This commit is contained in:
TachibanaKimika
2023-08-06 16:14:50 +08:00
parent 35baf17160
commit 65e0ff665d
2 changed files with 12 additions and 8 deletions

View File

@@ -349,11 +349,11 @@ class Config:
except:
return False
def number_regexs(self) -> list[str]:
def number_regexs(self) -> str:
try:
return self.conf.get("Name_Rule", "number_regexs").split()
return self.conf.get("Name_Rule", "number_regexs")
except:
return []
return ""
def update_check(self) -> bool:
try:
@@ -486,7 +486,7 @@ class Config:
conf.set(sec4, "max_title_len", "50")
conf.set(sec4, "image_naming_with_number", "0")
conf.set(sec4, "number_uppercase", "0")
conf.set(sec4, "number_regexs", [])
conf.set(sec4, "number_regexs", "")
sec5 = "update"
conf.add_section(sec5)

View File

@@ -41,10 +41,14 @@ def get_number(debug: bool, file_path: str) -> str:
# debug True 和 False 两块代码块合并原因是此模块及函数只涉及字符串计算没有IO操作debug on时输出导致异常信息即可
try:
# 先对自定义正则进行匹配
if config.getInstance().number_regexs():
for regex in config.getInstance().number_regexs():
if re.search(regex, filepath):
return re.search(regex, filepath).group()
if config.getInstance().number_regexs().split().__len__() > 0:
for regex in config.getInstance().number_regexs().split():
try:
if re.search(regex, filepath):
return re.search(regex, filepath).group()
except Exception as e:
print(f'[-]custom regex exception: {e} [{regex}]')
file_number = get_number_by_dict(filepath)
if file_number:
return file_number