forked from freyta/WWE-Network-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wwe.py
executable file
·205 lines (164 loc) · 7.25 KB
/
wwe.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
#!/usr/bin/python3
import os, sys
import subprocess
from time import time
import arrow, datetime
import requests, json, m3u8
import CONSTANTS
class wwe_network:
def __init__(self, user, password):
with requests.Session() as self._session:
self._session.headers.update(CONSTANTS.HEADERS)
self.user = user
self.password = password
self.logged_in = False
def _set_authentication(self):
access_token = self.authorisationToken
if not access_token:
print("No access token found.")
return
self._session.headers.update({'Authorization': 'Bearer {}'.format(access_token)})
print("Succesfully logged in")
self.logged_in = True
def login(self):
payload = {
"id": self.user,
"secret": self.password
}
token_data = self._session.post('https://dce-frontoffice.imggaming.com/api/v2/login', json=payload, headers=CONSTANTS.REALM_HEADERS).json()
if 'code' in token_data:
print("Error while logging in. Possibly invalid username/password")
exit()
self.authorisationToken = token_data['authorisationToken']
self.refreshToken = token_data['refreshToken']
self._set_authentication()
# Get the m3u8 stream
def m3u8_stream(self, stream_link):
#https://dve-api.imggaming.com/v/70800?customerId=16&auth=1f7512c7c2b7474abf723188038b32c1×tamp=1564126721496
stream = self._session.get(stream_link, headers=CONSTANTS.REALM_HEADERS).json()
return stream['hls']['url']
def get_chapter_information(self, link, episode_title, chapterize=False):
api_link = self._session.get('https://cdn.watch.wwe.com/api/page?path={}'.format(link)).json()
entry = api_link["entries"][0]["item"].get("relatedItems")
data = []
for i in entry:
if i.get("relationshipType") == "milestone":
start = int(i["item"]["customFields"].get("StartPoint") * 1000)
end = int(i["item"]["customFields"].get("EndPoint") * 1000)
title = i["item"].get("title")
data.append([start, end, title])
print("\nStarting to write the metadata file")
meta_file = open("{}/{}-metafile".format(CONSTANTS.TEMP_FOLDER, episode_title), "w")
meta_file.write(";FFMETADATA1\n\
title={}\n".format(episode_title))
print("Finished writing the metadata file")
if chapterize:
print("\nWriting chapter information")
for i in data:
meta_file.write("[CHAPTER]\n\
TIMEBASE=1/1000\n\
START={}\n\
END={}\n\
title={}\n\n".format(str(i[0]), str(i[1]), i[2]))
print("Finished writing chapter information")
print("\nStarting to write the stream title")
meta_file.write("[STREAM]\n\
title={}".format(episode_title))
print("Finished writing the stream title\n")
meta_file.close()
def _video_url(self, link):
#playerUrlCallback=https://dve-api.imggaming.com/v/70800?customerId=16&auth=33d8c27ac15ff76b0af3f2fbfc77ba05×tamp=1564125745670
video_url = self._session.get('https://dce-frontoffice.imggaming.com/api/v2/stream/vod/{}'.format(link), headers=CONSTANTS.REALM_HEADERS).json()
try:
if video_url['status'] == 403:
print("Your subscription is invalid. Quitting.")
exit()
except:
return video_url['playerUrlCallback'], video_url['videoId']
def get_video_info(self, link):
# Link: https://cdn.watch.wwe.com/api/page?path=/episode/This-Tuesday-in-Texas-1991-11831
# We need DiceVideoId
api_link = self._session.get('https://cdn.watch.wwe.com/api/page?path={}'.format(link)).json()
# If we have an invalid link, quit
try:
if api_link["message"]:
print("Video link is invalid. Exiting now..")
return
except:
pass
entry = api_link['entries'][0]['item']
# If our event is a weekly/episodic show, add the date, season and episode number to the file name
if entry["customFields"].get("EventStyle") == "Episodic":
if entry["episodeNumber"] < 10:
ep_num = "0" + str(entry["episodeNumber"])
else:
ep_num = entry["episodeNumber"]
file_date = arrow.get(
entry["firstBroadcastDate"], "YYYY-MM-DDTHH:mm:ssZ"
)
file_date = file_date.format("MM-DD-YYYY")
file_name = "{} {} - S{}E{} - {}".format(
entry["customFields"]["Franchise"],
entry["episodeName"]
.replace("&", "and")
.replace(":", "- ")
.replace("'", "")
.replace("\"", "")
.replace("/", " "),
entry["releaseYear"],
ep_num,
file_date,
)
elif entry["customFields"].get("SeasonNumber") and entry["customFields"].get("EventStyle") != "PPV":
if entry["episodeNumber"] < 10:
ep_num = "0" + str(entry["episodeNumber"])
else:
ep_num = entry["episodeNumber"]
file_date = arrow.get(
entry["firstBroadcastDate"], "YYYY-MM-DDTHH:mm:ssZ"
)
file_date = file_date.format("MM-DD-YYYY")
file_name = "{} - S{}E{} - {}".format(
entry["customFields"]["SeriesName"],
entry["customFields"].get("SeasonNumber"),
ep_num,
entry["episodeName"]
.replace("&", "and")
.replace(":", "- ")
.replace("'", "")
.replace("\"", "")
.replace("/", " "),
)
elif entry["customFields"].get("EventStyle") == "PPV":
# If it is a PPV get the title and year into variables
ppv_title = entry["episodeName"]
ppv_year = entry["releaseYear"]
# Check if the PPV already has the year in it. For example "This Tuesday in Texas 1991" has the year,
# but "WrestleMania 35" doesn't. Since we don't want to have "This Tuesday in Texas 1991 1991" as
# our filename we will just use the PPV title
if str(ppv_year) in ppv_title:
file_name = "{} {}".format(
entry["customFields"]["Franchise"], entry["episodeName"]
)
else:
file_name = "{} {} {}".format(
entry["customFields"]["Franchise"],
entry["episodeName"],
entry["releaseYear"],
)
else:
if not entry.get('title'):
raise Exception("Unrecognized event type")
file_name = (
entry["title"]
.replace("&", "and")
.replace(":", "- ")
.replace("'", "")
.replace("\"", "")
.replace("/", " ")
)
video_url_resp = self._video_url(api_link['entries'][0]['item']['customFields']['DiceVideoId'])
return video_url_resp[0], file_name, video_url_resp[1]
if __name__ == "__main__":
print("Please run python main.py instead.")
pass