-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanname.py
38 lines (33 loc) · 1.47 KB
/
cleanname.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import string
import re
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("directory", help="Directory to clean names of files of")
args = parser.parse_args()
ar = ['Episode 1','Episode 2','Episode 3', 'Episode 4', 'Episode 5', 'Episode 6', 'Episode 7', 'Episode 8', 'Episode 9', 'Episode 10', 'Episode 11', 'Episode 12']
dir = args.directory
files = os.listdir(dir)
for files in files:
if files.endswith(".mkv"):
strs = string.split(files, '.')
name = ''
pattern = '[S][0]'
pattern2 = 'X264.*'
for strs in strs:
if re.match(pattern, strs):
strs = string.replace(string.lstrip(strs, 'S0'), 'E', '')
name = name + ' - ' + strs + ' - ' + ar[string.atoi(strs[1:])-1]
elif strs == 'mkv' or strs == 'H' or strs == 'I' or strs == 'E' or strs == 'L' or strs == 'D' or strs == 'ini':
name = name + '.' + strs
elif strs == 'HDTV' or re.match(pattern2, strs) or strs == '720p' or strs == 'WEBRip' or strs == 'x264-W4F' or strs == 'x264-KILLERS' or strs == 'PROPER':
name = name
else:
name = name + ' ' + strs
name = string.strip(name)
num = str(int(string.split(strs[0],'title')[1]) + 8)
if int(num) < 10:
num = '0' + num
name = name + num + ' - ' + ar[int(num) - 1] + '.' + strs[1]
print name
os.rename(dir + '\\' + files, dir + '\\' + name)