From 3b81846df55d6f01b5432f9fbfd6eb5eb72d62be Mon Sep 17 00:00:00 2001 From: Carol Date: Thu, 31 Aug 2023 20:18:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carol --- python/changeFileName.py | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 python/changeFileName.py diff --git a/python/changeFileName.py b/python/changeFileName.py new file mode 100644 index 0000000..6650396 --- /dev/null +++ b/python/changeFileName.py @@ -0,0 +1,51 @@ +# -*- coding=utf-8 -*- +# @Time : 2023/1/14 13:22 +# @Author : LXW +# @File : changeFileName.py + +import os +import re +import sys + + +def change_file_suffix(input_file_path): + for parent_path, dir_path, filenames in os.walk(input_file_path): + for filename in filenames: + base_name = os.path.basename(parent_path) + result = re.search(base_name, filename) + if None is not result and not str(filename).endswith(".vsmeta"): + print(filename) + new_filename = filename.split(base_name + ".")[1] + os.rename(os.path.join(parent_path, filename), os.path.join(parent_path, new_filename)) + + +def delete_files(input_file_path): + for parent_path, dir_path, filenames in os.walk(input_file_path): + for filename in filenames: + if str(filename).endswith(".vsmeta"): + os.remove(os.path.join(parent_path, filename)) + + +def change_naruto(input_file_path): + for parent_path, dir_path, filenames in os.walk(input_file_path): + for filename in filenames: + base_name = os.path.basename(parent_path) + result = re.search(base_name, filename) + if None is not result and not str(filename).endswith(".vsmeta") and not str(filename).endswith(".srt") and not str(filename).endswith(".ass"): + print(filename) + first_split = filename.split("[西行纪][The Westward][") + if len(first_split) > 1: + # number = first_split[1].split(".")[0].replace(" ", "") + # new_filename = base_name+"."+number+".mp4" + + number = first_split[1] + new_number = number.split("]")[0] + new_filename = "西行纪.The Westward.S01E" + new_number + ".mp4" + os.rename(os.path.join(parent_path, filename), os.path.join(parent_path, new_filename)) + + +if __name__ == '__main__': + # __input_file_path = sys.argv[1] + __input_file_path = "F:\download\西行纪" + change_naruto(input_file_path=__input_file_path) + delete_files(input_file_path=__input_file_path)