本页面由 Typecho 创建, 这只是个测试页面.


介绍

这里是Daybreak博客!什么都不想写的博客欸:+1:

关于

写啥?

#代码高亮测试
from time import sleep
import re
import os

MATCH_REGEX = re.compile(r'^.+\[(\d{2})\].*?\.(\w{0,3})$')
REMOVE_ERROR_FILE = False
# MATCH_REGEX_NEW = re.compile(r'')

fileMatched = {}
for i in os.listdir(os.getcwd()):
    if MATCH_REGEX.match(i):
        splited = MATCH_REGEX.findall(i)[0]
        if not fileMatched.get(splited[0]):
            fileMatched[splited[0]] = {'mkv': [], 'ass': []}
        fileMatched[splited[0]][splited[-1]].append(i)
# print(str(fileMatched))

nameChange = []
for perSerial in fileMatched:
    print(perSerial)
    i = fileMatched[perSerial]
    if len(i['mkv'][0].split('.')) >= 3:
        originName = ''.join(i['mkv'][0].split('.')[0:-2])
    else:
        originName = ''.join(i['mkv'][0].split('.')[0])
    for i in i['ass']:
        splitedName = i.split('.')
        newSplitedName = i.split('.')
        if len(i.split('.')) >= 3:
            newSplitedName[0:-2] = originName
            oldName = '.'.join(splitedName)
            newName = ''.join(newSplitedName[0:-2])
            del newSplitedName[0:-2]
            newName = newName + '.'.join(newSplitedName)
            # print(oldName,newName)
        else:
            newSplitedName[0] = originName
            oldName = '.'.join(splitedName)
            newName = '.'.join(newSplitedName)
        nameChange.append((oldName, newName))

for i in nameChange:
    print('Will Change "%s" to "%s".' % i)
    try:
        os.rename(i[0], i[1])
    except FileExistsError as e:
        print('Failed To Chage,Reason:"%s"' % e)
        if REMOVE_ERROR_FILE is True:
            os.remove(i[0])
        elif REMOVE_ERROR_FILE is False:
            pass
        else:
            raise TypeError
    sleep(1)