分享一个重命名脚本,针对VCB/DBD压制组的 #699
AiharaMahiru
started this conversation in
Ideas
Replies: 3 comments 4 replies
-
对目录摆放有一定要求,重命名后符合Emby规则 |
Beta Was this translation helpful? Give feedback.
0 replies
-
感谢。 |
Beta Was this translation helpful? Give feedback.
4 replies
-
脚本更新,抽取了函数,增加了识别范围 import os
import re
def normalize_language_code(language_code):
simplified_codes = ['[chs]', '[CHS]', '[SC]', 'SC', 'sc', 'JPSC', 'jpsc', '.chs', '.sc', '.jpsc']
traditional_codes = ['[cht]', '[CHT]', '[TC]', 'TC', 'tc', 'JPTC', 'jptc', '.cht', '.tc', '.jptc']
if language_code in simplified_codes:
return '.chs'
elif language_code in traditional_codes:
return '.cht'
else:
return ''
def is_subtitle_file(file_name):
subtitle_extensions = ['.ass', '.srt', '.ssa', '.sub', '.smi', '.vtt']
_, extension = os.path.splitext(file_name)
return extension.lower() in subtitle_extensions
def rename_files_in_directory(directory_path):
for root, dirs, files in os.walk(directory_path):
parts = root.split(os.sep)
if len(parts) < 2:
continue
series_name = parts[-2]
season_number = parts[-1].split(' ')[-1]
for file_name in files:
match = re.search(r'(?:(?:\[|\bS\d+E)(\d+)|- (\d+))(.*?)(\[CHS\]|\[CHT\]|\[SC\]|SC|sc|JPSC|jpsc|\[TC\]|TC|tc|JPTC|jptc|\.chs|\.cht|\.sc|\.tc|\.jpsc|\.jptc)?(\..+)$', file_name, re.IGNORECASE)
if not match:
print(f"Could not match episode or language code in '{file_name}'. Skipping...")
continue
episode_number = match.group(1) if match.group(1) else match.group(2)
language_code = match.group(4) or ''
file_extension = match.group(5)
if is_subtitle_file(file_name):
language = normalize_language_code(language_code)
if not language:
# 如果没有检测到语言标识,则默认为简体中文
language = '.chs'
new_name = f"{series_name} S{season_number.zfill(2)}E{episode_number.zfill(2)}{language}{file_extension}"
else:
new_name = f"{series_name} S{season_number.zfill(2)}E{episode_number.zfill(2)}{file_extension}"
old_path = os.path.join(root, file_name)
new_path = os.path.join(root, new_name)
if os.path.exists(new_path):
print(f"File '{new_path}' already exists. Skipping '{file_name}'...")
continue
print(f"Renaming '{file_name}' to '{new_name}'")
os.rename(old_path, new_path)
# directory_path = input("Enter the directory path: ")
directory_path = "F:\Anime\彼得·格里尔的贤者时间"
rename_files_in_directory(directory_path)
print("Renaming completed.") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Beta Was this translation helpful? Give feedback.
All reactions