Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加自定义正则 & 番号大写转换配置 #1059

Merged
merged 4 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: 添加自定义正则 & 番号大写转换配置
  • Loading branch information
TachibanaKimika committed Aug 6, 2023
commit e23a25b9b7005004ed8e71c6a08bbe6325725657
3 changes: 3 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ naming_rule = number+'-'+title
max_title_len = 50
; 刮削后图片是否命名为番号
image_naming_with_number = 0
; 番号大写(仅在写入文件时变大写, 搜索时不影响)
number_uppercase = 0
number_regexs =

[update]
update_check = 1
Expand Down
14 changes: 14 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ def image_naming_with_number(self) -> bool:
except:
return False

def number_uppercase(self) -> bool:
try:
return self.conf.getboolean("Name_Rule", "number_uppercase")
except:
return False

def number_regexs(self) -> list[str]:
try:
return self.conf.get("Name_Rule", "number_regexs").split()
except:
return []

def update_check(self) -> bool:
try:
return self.conf.getboolean("update", "update_check")
Expand Down Expand Up @@ -473,6 +485,8 @@ def _default_config() -> configparser.ConfigParser:
conf.set(sec4, "naming_rule", "number + '-' + title")
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", [])

sec5 = "update"
conf.add_section(sec5)
Expand Down
5 changes: 5 additions & 0 deletions number_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def get_number(debug: bool, file_path: str) -> str:
filepath = os.path.basename(file_path)
# 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()
file_number = get_number_by_dict(filepath)
if file_number:
return file_number
Expand Down
4 changes: 4 additions & 0 deletions scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def get_data_from_json(
series = json_data.get('series')
year = json_data.get('year')


if conf.number_uppercase():
number = number.upper()

if json_data.get('cover_small'):
cover_small = json_data.get('cover_small')
else:
Expand Down