AI办公自动化:deepseek批量统一文件标题的命名格式

2024-08-08 12:10:11 浏览数 (2)

多种命名格式:

统一为这样:

Deepseek中输入提示词:

你是一个Python编程专家,写一个Python脚本,具体步骤如下:

打开文件夹:E:1-7

读取文件中的Mp3文件;

重命名文件:

如果mp3文件名中有字符“HTTYDBAR.FANSUB.DRAGONS.RACE.TO.THE.EDGE.S”,将mp3音频文件的主文件名中的“HTTYDBAR.FANSUB.DRAGONS.RACE.TO.THE.EDGE.S”替换为“Dragons.S03E”,将主文件名中的“1080P”删除掉;

如果mp3文件名中有字符“驯龙记:飞越边界-”,将mp3音频文件的主文件名中的“驯龙记:飞越边界-”替换为“Dragons.S03E”;

如果mp3文件名中有字符“【中英双字】【驯龙高手吧字幕组】”,将mp3音频文件的主文件名中的“【中英双字】【驯龙高手吧字幕组】TV6第{number}集”替换为“Dragons.S03E{{number} 39}”,{number}的值是从1到13

举个例子:

原文件名:HTTYDBAR.FANSUB.DRAGONS.RACE.TO.THE.EDGE.S18.1080P.mp3,重命名为:Dragons.S03E18.mp3

原文件名:驯龙记:飞越边界-27 Enemy of my Enemy.mp3,重命名为:Dragons.S03E27 Enemy of my Enemy.mp3

原文件名:【中英双字】【驯龙高手吧字幕组】TV6第1集.mp3,重命名为:Dragons.S03E40.mp3

注意:每一步都要输出信息到屏幕上

源代码:

import os

import re

def rename_mp3_files(directory):

for filename in os.listdir(directory):

if filename.endswith('.mp3'):

full_path = os.path.join(directory, filename)

new_filename = filename

# Check and replace "HTTYDBAR.FANSUB.DRAGONS.RACE.TO.THE.EDGE.S"

if "HTTYDBAR.FANSUB.DRAGONS.RACE.TO.THE.EDGE.S" in filename:

new_filename = re.sub(r"HTTYDBAR.FANSUB.DRAGONS.RACE.TO.THE.EDGE.S(d ).1080P", r"Dragons.S03E1", filename)

# Check and replace "驯龙记:飞越边界-"

if "驯龙记:飞越边界-" in filename:

new_filename = re.sub(r"驯龙记:飞越边界-(d )", r"Dragons.S03E1", filename)

# Check and replace "【中英双字】【驯龙高手吧字幕组】"

if "【中英双字】【驯龙高手吧字幕组】" in filename:

match = re.search(r"【中英双字】【驯龙高手吧字幕组】TV6第(d )集", filename)

if match:

number = int(match.group(1))

new_filename = re.sub(r"【中英双字】【驯龙高手吧字幕组】TV6第d 集", f"Dragons.S03E{number 39}", filename)

if new_filename != filename:

new_full_path = os.path.join(directory, new_filename)

os.rename(full_path, new_full_path)

print(f"Renamed: {filename} -> {new_filename}")

else:

print(f"No changes: {filename}")

if __name__ == "__main__":

directory = "E:\1-7"

rename_mp3_files(directory)

0 人点赞