Created
October 8, 2019 08:59
-
-
Save freyta/6aebc60cf372b77f4387287d2e9ac5bb to your computer and use it in GitHub Desktop.
WWE Downloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wwe | |
import json | |
import subprocess | |
import m3u8 | |
import argparse | |
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("_") | |
# GET ARGS FOR EPISODE TO DOWNLOAD | |
parser = argparse.ArgumentParser(description='Download videos off the WWE Network') | |
parser.add_argument('-t','--title', help='Title of the video you want to download. Example: /episode/Prime-Time-Wrestling-9283', required=True) | |
args = vars(parser.parse_args()) | |
if args['title']: | |
EPISODE = args['title'] | |
# If the title wasn't set | |
if not EPISODE: | |
print("You episode found. Use the --title parameter.") | |
exit() | |
# Prefix a / if we haven't included it in our title | |
if EPISODE.startswith("e") or EPISODE.startswith("w"): | |
EPISODE = "/" + EPISODE | |
# Login | |
account = wwe.wwe_network("[email protected]","password") | |
account.login() | |
print("Logged in") | |
# Get the video JSON which tells us the hls url link | |
video_link = account.get_video_info(EPISODE) | |
# Grab the m3u8 | |
stream_url = account.m3u8_stream(video_link[0]) | |
title = video_link[1] | |
print("Got video information") | |
# To download the video using ffmpeg | |
#print('ffmpeg -user_agent "WWE/4.0.13 (Linux;Android 9) ExoPlayerLib/2.9.3" -i "' + stream_url + '" -c copy ' + make_safe_filename(title) + '.mp4 -y') | |
# To see what streams are available using ffrprobe | |
#print('ffprobe -user_agent "WWE/4.0.13 (Linux;Android 9) ExoPlayerLib/2.9.3" -i "' + stream_url + '"') | |
# If you want to view the formats available to download | |
#subprocess.call("youtube-dl -k -f --verbose --hls-prefer-native --fixup never --add-header User-Agent:\"WWE/4.0.13 (Linux;Android 9) ExoPlayerLib/2.9.3\" \"{}\" -o \"{}\".mp4".format(stream_url, make_safe_filename(title)), shell=True) | |
# If you want to download the video | |
#subprocess.call("youtube-dl --verbose --hls-prefer-native --fixup never --add-header User-Agent:\"WWE/4.0.13 (Linux;Android 9) ExoPlayerLib/2.9.3\" \"{}\" -o \"{}\".mp4".format(stream_url, make_safe_filename(title)), shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import os | |
import subprocess | |
from time import time | |
import json | |
import requests | |
import arrow | |
HEADERS = { | |
'User-Agent': 'okhttp/3.12.1' | |
} | |
REALM_HEADERS = { | |
'x-api-key': '640a69fb-68b1-472c-ba4b-36f50288c984', | |
'realm': 'dce.wwe' | |
} | |
DICE_MOBILE_API_KEY = '640a69fb-68b1-472c-ba4b-36f50288c984' | |
class wwe_network: | |
def __init__(self, user, password): | |
with requests.Session() as self._session: | |
self._session.headers.update(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)}) | |
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=REALM_HEADERS).json() | |
if 'code' in token_data: | |
print("Error - {}".format(token_data.get('messages'))) | |
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=REALM_HEADERS).json() | |
print(stream['hlsUrl']) | |
return stream['hls']['url'] | |
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=REALM_HEADERS).json() | |
return video_url['playerUrlCallback'] | |
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() | |
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']['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('M-DD-YYYY') | |
file_name = '{} {} - S{}E{} - {}'.format(entry['customFields']['Franchise'], | |
entry['episodeName'], | |
entry['releaseYear'], | |
ep_num, | |
file_date) | |
else: | |
# Since we have 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']) | |
return self._video_url(api_link['entries'][0]['item']['customFields']['DiceVideoId']), file_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment