forked from freyta/WWE-Network-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kodi_nfo.py
227 lines (192 loc) · 7.31 KB
/
kodi_nfo.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/python3
import CONSTANTS, os
import json, random
import requests
import arrow
def make_safe_filename(s):
def safe_char(c):
if c.isalnum():
return c
else:
return "_"
return "".join(safe_char(c) for c in s).rstrip("_")
def create_multi_ep_nfo(show_list):
print(show_list)
id = []
for i in show_list:
try:
# Get the show JSON file
show_json = requests.get('https://cdn.watch.wwe.com/api/page?path={}'.format(i)).json()
entry = show_json['entries'][0]['item']
#try:
# .title() makes JUL turn into Jul - camelcase.
title = '{} {} - {}'.format(entry['customFields']['Franchise'], entry['episodeName'], entry['metadataLines'][0]['lines'][1].title())
try:
plot = entry['description']
except:
plot = ""
description = entry['shortDescription']
episode = entry['episodeNumber']
mpaa = entry['classification']['name']
aired = entry['firstBroadcastDate'][:10]
season = entry['releaseYear']
# WWE Raw - S20E01 - 1-02-2012.avi
file_date = arrow.get(entry['firstBroadcastDate'],'YYYY-MM-DDTHH:mm:ss')
file_date = file_date.format('M-DD-YYYY')
if(entry['episodeNumber'] < 10):
ep_num = "0" + str(entry['episodeNumber'])
else:
ep_num = entry['episodeNumber']
file_name = '{} {} - S{}E{} - {}'.format(entry['customFields']['Franchise'],
entry['episodeName'],
entry['releaseYear'],
ep_num,
file_date)
# FORMAT:
# 0 = title
# 1 - Year + Season
# 2 - Episode
# 3 - Outline
# 4 - Plot
# 5 - aired
nfo_text = "<episodedetails>\n\
<title>{0}</title>\n\
<season>{1}</season>\n\
<episode>{2}</episode>\n\
<outline>{3}</outline>\n\
<plot>{4}</plot>\n\
<id></id>\n\
<genre>Sport</genre>\n\
<year>{1}</year>\n\
<aired>{5}</aired>\n\
<studio>WWE Network</studio>\n\
<trailer></trailer>\n\
</episodedetails>".format(title,season,episode,description,plot,aired)
#f= open("{}.nfo".format(file_name),"w+")
#f.write(nfo_text)
#print("{} is done".format(file_name))
except:
print("failed")
pass
return nfo_text, file_name
def create_episode_nfo(url, series_folder, file_name = None):
id = []
# Get the show JSON file
show_json = requests.get('https://cdn.watch.wwe.com/api/page?path={}'.format(url)).json()
entry = show_json['entries'][0]['item']
#try:
# .title() makes JUL turn into Jul - camelcase.
title = entry['title']
try:
plot = entry['description']
except:
plot = ""
description = entry['shortDescription']
if(description == "-1"):
description = plot
try:
episode = entry['episodeNumber']
except KeyError:
episode = 0
# Some episodes are specials which haven't got an episode number
# i.e. https://watch.wwe.com/episode/Best-Stunner-reactions-WWE-Top-10-March-15-2020-132341
if episode <= 0:
episode = 0
mpaa = entry['classification']['name']
aired = entry['firstBroadcastDate'][:10]
season = entry['releaseYear']
# WWE Raw - S20E01 - 1-02-2012.avi
file_date = arrow.get(entry['firstBroadcastDate'],'YYYY-MM-DDTHH:mm:ssZ')
file_date = file_date.format('M-DD-YYYY')
try:
if(entry['episodeNumber'] < 10):
ep_num = "0" + str(entry['episodeNumber'])
else:
ep_num = entry['episodeNumber']
except KeyError:
ep_num = 0
if (entry.get('episodeNumber') == '0'):
ep_num = "00"
if not file_name:
file_name = '{} {} - S{}E{} - {}'.format(entry['customFields']['Franchise'],
entry['episodeName'],
entry['releaseYear'],
ep_num,
file_date)
# FORMAT:
# 0 = title
# 1 - Year + Season
# 2 - Episode
# 3 - Outline
# 4 - Plot
# 5 - aired
nfo_text = "<episodedetails>\n\
<title>{0}</title>\n\
<season>{1}</season>\n\
<episode>{2}</episode>\n\
<outline>{3}</outline>\n\
<plot>{4}</plot>\n\
<id></id>\n\
<genre>Sport</genre>\n\
<year>{1}</year>\n\
<aired>{5}</aired>\n\
<studio>WWE Network</studio>\n\
<trailer></trailer>\n\
</episodedetails>".format(title,season,episode,description,plot,aired)
if not os.path.isdir("./{}/{}".format(CONSTANTS.OUTPUT_FOLDER,series_folder)):
os.mkdir("./{}/{}".format(CONSTANTS.OUTPUT_FOLDER,series_folder))
f= open(CONSTANTS.OUTPUT_FOLDER + "/" + series_folder + "/{}.nfo".format(file_name),"w+")
f.write(nfo_text)
# Create a Kodi compliant NFO file
def create_show_nfo(nfo_text, title, wallpaper, poster):
print(title)
f= open(CONSTANTS.OUTPUT_FOLDER + "/" + title + "/tvshow.nfo", "w+")
f.write(nfo_text)
# Download the fanart
image = requests.get(wallpaper)
open(CONSTANTS.OUTPUT_FOLDER + "/" + title + "/fanart.png", "wb").write(image.content)
print("Saved fanart")
# Download the poster
image = requests.get(poster)
open(CONSTANTS.OUTPUT_FOLDER + "/" + title + "/poster.png", "wb").write(image.content)
print("Saved poster")
# Get the basics for our Kodi NFO and the series name
def get_show_info(link):
URL = "https://cdn.watch.wwe.com/api/page?list_page_size=100&path={}&item_detail_expand=all".format(link)
show_json = requests.get(URL).json()
#try:
# NEW_URL = "https://cdn.watch.wwe.com/api/page?list_page_size=100&path={}&item_detail_expand=all".format(show_json['entries'][0]['item']['season']['path'])
# print(NEW_URL)
# show_json = requests.get(NEW_URL).json()
#except KeyError:
# pass
#f = open("test.txt","w")
#f.write(json.dumps(show_json, indent=4))
#exit()
i = show_json['entries'][0]['item']
franchise = i['customFields']['Franchise']
title = i['title']
if franchise not in title[:len(franchise)]:
title = "{} {}".format(i['customFields']['Franchise'], i['title'])
description = i['description']
mpaa = i['classification']['name']
# FORMAT:
# 0 = title
# 1 - description
# 2 - mpaa
nfo_text = "<tvshow>\n\
<title>{0}</title>\n\
<showtitle>{0}</showtitle>\n\
<userrating>{3}</userrating>\n\
<outline>{1}</outline>\n\
<plot>{1}</plot>\n\
<mpaa>{2}</mpaa>\n\
<genre>Sports</genre>\n\
<studio>WWE Network</studio>\n\
</tvshow>".format(title,description,mpaa,random.randint(5,10))
wallpaper = i['images']['wallpaper']
poster = i['images']['poster']
return title, nfo_text, wallpaper, poster
if __name__ == "__main__":
print("Please run python main.py instead.")
pass