Merge pull request #1059 from TachibanaKimika/master
添加自定义正则 & 番号大写转换配置
This commit is contained in:
@@ -53,6 +53,11 @@ naming_rule = number+'-'+title
|
|||||||
max_title_len = 50
|
max_title_len = 50
|
||||||
; 刮削后图片是否命名为番号
|
; 刮削后图片是否命名为番号
|
||||||
image_naming_with_number = 0
|
image_naming_with_number = 0
|
||||||
|
; 番号大写 1 | 0, 仅在写入数据时会进行大写转换, 搜索刮削流程则不影响
|
||||||
|
number_uppercase = 0
|
||||||
|
; 自定义正则表达式, 多个正则使用空格隔开, 第一个分组为提取的番号, 若自定义正则未能匹配到番号则使用默认规则
|
||||||
|
; example: ([A-Za-z]{2,4}\-\d{3}) ([A-Za-z]{2,4}00\d{3})
|
||||||
|
number_regexs =
|
||||||
|
|
||||||
[update]
|
[update]
|
||||||
update_check = 1
|
update_check = 1
|
||||||
|
|||||||
14
config.py
14
config.py
@@ -343,6 +343,18 @@ class Config:
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def number_uppercase(self) -> bool:
|
||||||
|
try:
|
||||||
|
return self.conf.getboolean("Name_Rule", "number_uppercase")
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def number_regexs(self) -> str:
|
||||||
|
try:
|
||||||
|
return self.conf.get("Name_Rule", "number_regexs")
|
||||||
|
except:
|
||||||
|
return ""
|
||||||
|
|
||||||
def update_check(self) -> bool:
|
def update_check(self) -> bool:
|
||||||
try:
|
try:
|
||||||
return self.conf.getboolean("update", "update_check")
|
return self.conf.getboolean("update", "update_check")
|
||||||
@@ -473,6 +485,8 @@ class Config:
|
|||||||
conf.set(sec4, "naming_rule", "number + '-' + title")
|
conf.set(sec4, "naming_rule", "number + '-' + title")
|
||||||
conf.set(sec4, "max_title_len", "50")
|
conf.set(sec4, "max_title_len", "50")
|
||||||
conf.set(sec4, "image_naming_with_number", "0")
|
conf.set(sec4, "image_naming_with_number", "0")
|
||||||
|
conf.set(sec4, "number_uppercase", "0")
|
||||||
|
conf.set(sec4, "number_regexs", "")
|
||||||
|
|
||||||
sec5 = "update"
|
sec5 = "update"
|
||||||
conf.add_section(sec5)
|
conf.add_section(sec5)
|
||||||
|
|||||||
@@ -40,6 +40,15 @@ def get_number(debug: bool, file_path: str) -> str:
|
|||||||
filepath = os.path.basename(file_path)
|
filepath = os.path.basename(file_path)
|
||||||
# debug True 和 False 两块代码块合并,原因是此模块及函数只涉及字符串计算,没有IO操作,debug on时输出导致异常信息即可
|
# debug True 和 False 两块代码块合并,原因是此模块及函数只涉及字符串计算,没有IO操作,debug on时输出导致异常信息即可
|
||||||
try:
|
try:
|
||||||
|
# 先对自定义正则进行匹配
|
||||||
|
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)
|
file_number = get_number_by_dict(filepath)
|
||||||
if file_number:
|
if file_number:
|
||||||
return file_number
|
return file_number
|
||||||
|
|||||||
@@ -165,6 +165,10 @@ def get_data_from_json(
|
|||||||
cover_small = tmpArr[0].strip('\"').strip('\'')
|
cover_small = tmpArr[0].strip('\"').strip('\'')
|
||||||
# ====================处理异常字符 END================== #\/:*?"<>|
|
# ====================处理异常字符 END================== #\/:*?"<>|
|
||||||
|
|
||||||
|
# 处理大写
|
||||||
|
if conf.number_uppercase():
|
||||||
|
json_data['number'] = number.upper()
|
||||||
|
|
||||||
# 返回处理后的json_data
|
# 返回处理后的json_data
|
||||||
json_data['title'] = title
|
json_data['title'] = title
|
||||||
json_data['original_title'] = title
|
json_data['original_title'] = title
|
||||||
|
|||||||
Reference in New Issue
Block a user