Skip to content

Commit

Permalink
🎨 优化查找主体的能力 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
KimigaiiWuyi committed Sep 11, 2024
1 parent 13ae7ab commit 9fb7e45
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,8 @@ cython_debug/
#.idea/

output
test.py
test.py
Bangumi_Auto_Rename.build
Bangumi_Auto_Rename.exe
Bangumi_Auto_Rename.dist
Bangumi_Auto_Rename.onefile-build
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "Bangumi_Auto_Rename"
version = "0.1.0"
version = "0.2.1"
description = "Default template for PDM package"
authors = [
{name = "KimigaiiWuyi", email = "[email protected]"},
Expand Down
27 changes: 24 additions & 3 deletions src/Bangumi_Auto_Rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,28 @@ def remove_code(s: str) -> str:
return s


def remove_tag(s: str):
for pattern in bracket_patterns:
s = re.sub(pattern, '', s)
def remove_tag(s: str, skip=False):
if skip:
# 创建一个字典来追踪每种括号的匹配次数
counts = {pattern: 0 for pattern in bracket_patterns}

# 定义替换函数,追踪匹配次数并决定是否保留第二个匹配
def replace_match(pattern, match):
counts[pattern] += 1
# 保留每种括号的第二个匹配,否则去除
if counts[pattern] == 2:
return match.group(0)
else:
return ''

# 对每个模式应用相应的匹配逻辑
for pattern in bracket_patterns:
s = re.sub(pattern, lambda m: replace_match(pattern, m), s)
else:
# 不启用跳过规则,正常删除所有匹配项
for pattern in bracket_patterns:
s = re.sub(pattern, '', s)

return s.strip()


Expand Down Expand Up @@ -413,6 +432,8 @@ def process_path(path: Path, R: Dict[Path, Path]):
'''
# 允许处理单独视频情况
rtpath_name = remove_tag(path.name)
if not rtpath_name:
rtpath_name = remove_tag(path.name, True)
path_atri = re.split(r'[\s-]+', rtpath_name)
if len(path_atri) > 3:
# path_atri.pop(0)
Expand Down

0 comments on commit 9fb7e45

Please sign in to comment.