-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.py
94 lines (87 loc) · 3.52 KB
/
script.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import sys
sys.path.insert(0, "./cinemagoer")
import imdb
invalid_characters="~\"#%&*:<>?/\{|}"
ia=imdb.IMDb()
series_id=input("Enter series ID (Number preceeding tt in the IMDb's series URL): ")
series=ia.get_movie(series_id)
ia.update(series, 'episodes')
seasons=sorted(series['episodes'].keys())
episodes=series.data['episodes']
series_path=input("Enter series absolute path (The directory carrying the seasons' directories sorted): ")
series_path=os.path.abspath(series_path)
os.chdir(series_path)
for i in seasons:
if i<10:
try:
season_path=os.path.join(series_path, "0"+str(i))
os.chdir(season_path)
except FileNotFoundError:
break
else:
try:
season_path=os.path.join(series_path, str(i))
os.chdir(season_path)
except FileNotFoundError:
break
j=1
for k in sorted(os.listdir()):
try:
episode=series['episodes'][i][j]
except KeyError:
break
title=episode['title']
ext=os.path.splitext(k)[1]
if i<10:
if j<10:
try:
os.rename(k, "S0"+str(i)+"E0"+str(j)+"."+title+ext)
except OSError:
print("Inavlid title: "+k+" -> "+"S0"+str(i)+"E0"+str(j)+"."+title+ext)
for c in title:
if c in invalid_characters:
title=title.replace(c, "")
os.rename(k, "S0"+str(i)+"E0"+str(j)+"."+title+ext)
print("Title modified: "+"S0"+str(i)+"E0"+str(j)+"."+title+ext+"\n")
else:
pass
else:
try:
os.rename(k, "S0"+str(i)+"E"+str(j)+"."+title+ext)
except OSError:
print("Inavlid title: "+k+" -> "+"S0"+str(i)+"E"+str(j)+"."+title+ext)
for c in title:
if c in invalid_characters:
title=title.replace(c, "")
os.rename(k, "S0"+str(i)+"E"+str(j)+"."+title+ext)
print("Title modified: "+"S0"+str(i)+"E"+str(j)+"."+title+ext+"\n")
else:
pass
else:
if j<10:
try:
os.rename(k, "S"+str(i)+"E0"+str(j)+"."+title+ext)
except OSError:
print("Inavlid title: "+k+" -> "+"S"+str(i)+"E0"+str(j)+"."+title+ext)
for c in title:
if c in invalid_characters:
title=title.replace(c, "")
os.rename(k, "S"+str(i)+"E0"+str(j)+"."+title+ext)
print("Title modified: "+"S"+str(i)+"E0"+str(j)+"."+title+ext+"\n")
else:
pass
else:
try:
os.rename(k, "S"+str(i)+"E"+str(j)+"."+title+ext)
except OSError:
print("Inavlid title: "+k+" -> "+"S"+str(i)+"E"+str(j)+"."+title+ext)
for c in title:
if c in invalid_characters:
title=title.replace(c, "")
os.rename(k, "S"+str(i)+"E"+str(j)+"."+title+ext)
print("Title modified: "+"S"+str(i)+"E"+str(j)+"."+title+ext+"\n")
else:
pass
j+=1
print("Done!")