Rename file using the part of the Subtitle's title.

JeyS·2020년 6월 3일

Python Exec

목록 보기
3/3
import os
import os.path
import re
path = r"L:\ANI\Batman The Animated Series"
pathsub = r"D:\Downloads\Subtiltle relation\Batman+The+Animated+Series"
flist = os.listdir(path)
sublist = os.listdir(pathsub)
#flistmkv = []
#flistre = []
#subre = []

for f in flist:
    if f.startswith(r'Batman.') and f.endswith('.mkv'):
        fsli = f[34:-35]
        f_re = fsli.replace('.', '').replace('PartTwo','PartII').replace('PartOne','').replace('-','')    #replace함수를 이용한 문자열 치환
        print('replace f_re : '+f_re)
        #f_rename = f[:-4]
        #f_re = re.sub('[PartTwo]','II', re.sub('[ .-]', '', f))  #re.sub을 활용한 문자열 치환, 변환된 객체는 재대입해야함(i=i)
        #f_sli_re = f_re[29:-30]
        #flistre.append(f_sli)
    
        for subf in sublist:
            if subf.endswith('.smi'):
                sub_rename = subf[:-4]      # mkv파일의 대체될 이름
                subfsli = subf[32:-4]
                sub_af_re = re.sub(',','', re.sub("'", '', re.sub('[ .]', '', subfsli)))
                
                #sub_af_slice_re = sub_af_re[26:-3]
                ##subre.append(subf)
                if sub_af_re == f_re:
                    os.rename(os.path.join(path, f), os.path.join(path, sub_rename+'.mkv'))
                    #print('sub_re : '+sub_af_re)
                    print('sub_re : '+ subf + ' => '+ f)
                                        # rename은 현재 디렉토리 경로를 참조함. list는 전체경로를 담지 않기에 join함수로 전체 경로를 붙여줘야한다.
                #elif sub_af_re.startswith(f_re):
                #    os.rename(os.path.join(path, f), os.path.join(path, sub_rename+'.mkv'))

                

#print(flistre)
#print(sub_af_slice)

삽질의 삽질의 삽질의..

0개의 댓글