mirror of
https://github.com/hanxi/xiaomusic.git
synced 2026-03-18 08:43:17 +08:00
fix: 修复歌曲批量重命名的问题
This commit is contained in:
@@ -1,8 +1,29 @@
|
||||
from xiaomusic.utils import (
|
||||
remove_common_prefix,
|
||||
)
|
||||
import re
|
||||
|
||||
|
||||
def removepre(filename):
|
||||
match = re.search(r"^(\d+)\s+\d*(.+?)\.(.*$)", filename.strip())
|
||||
new_filename = filename
|
||||
if match:
|
||||
num = match.group(1)
|
||||
name = match.group(2).replace(".", " ").strip()
|
||||
suffix = match.group(3)
|
||||
# print(name)
|
||||
# print(num)
|
||||
# print(suffix)
|
||||
new_filename = f"{num}.{name}.{suffix}"
|
||||
|
||||
print(filename, "=>", new_filename)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
remove_common_prefix(
|
||||
"./tmp/【无损音质】2024年9月酷狗热歌榜TOP100合集(只选热歌最高的)首首王炸,分P合集!"
|
||||
)
|
||||
removepre(" 17 《白色风车》.mp3")
|
||||
removepre(" 17 《白色风车》.mp3")
|
||||
removepre(" 17 17 《白色风车》.mp3")
|
||||
removepre(" 17 17 《白色风车》.mp3")
|
||||
|
||||
removepre(" 18 风车.mp3")
|
||||
removepre(" 18 色风车.mp3")
|
||||
removepre(" 18 18 你好.mp3")
|
||||
removepre(" 18 18 我好.mp3")
|
||||
removepre("09 009. 梁静茹-亲亲.mp3")
|
||||
|
||||
@@ -965,7 +965,7 @@ def remove_common_prefix(directory):
|
||||
|
||||
log.info(f'Common prefix identified: "{common_prefix}"')
|
||||
|
||||
pattern = re.compile(r"(\d+)[\t ]*\1")
|
||||
pattern = re.compile(r"^(\d+)\s+\d*(.+?)\.(.*$)")
|
||||
for filename in files:
|
||||
if filename == common_prefix:
|
||||
continue
|
||||
@@ -973,9 +973,12 @@ def remove_common_prefix(directory):
|
||||
if filename.startswith(common_prefix):
|
||||
# 构造新的文件名
|
||||
new_filename = filename[len(common_prefix) :]
|
||||
match = pattern.match(new_filename)
|
||||
match = pattern.search(new_filename.strip())
|
||||
if match:
|
||||
new_filename = match.group(1) + new_filename[match.end() :]
|
||||
num = match.group(1)
|
||||
name = match.group(2).replace(".", " ").strip()
|
||||
suffix = match.group(3)
|
||||
new_filename = f"{num}.{name}.{suffix}"
|
||||
# 生成完整的文件路径
|
||||
old_file_path = os.path.join(directory, filename)
|
||||
new_file_path = os.path.join(directory, new_filename)
|
||||
|
||||
Reference in New Issue
Block a user