Skip to content

Instantly share code, notes, and snippets.

@chrippa
Created November 8, 2013 02:15
Show Gist options
  • Save chrippa/7365227 to your computer and use it in GitHub Desktop.
Save chrippa/7365227 to your computer and use it in GitHub Desktop.
Livestreamer plugin for Blizzcon esport streams, valid urls: blizzcon://sc2 blizzcon://wow blizzcon://esports
from livestreamer.plugin import Plugin
from livestreamer.stream import HTTPStream
from livestreamer.utils import urlget, parse_json, res_xml
import re
CHANNELS = {
"sc2": ["blizzcon2013_scii_d1_ah_l",
"blizzcon2013_scii_d1_ah_m",
"blizzcon2013_scii_d1_ah_h"],
"wow": ["blizzcon2013_wow_d1_ah_l",
"blizzcon2013_wow_d1_ah_m",
"blizzcon2013_wow_d1_ah_h"],
"esports": ["blizzcon2013_esports_d1_ah_l",
"blizzcon2013_esports_d1_ah_m",
"blizzcon2013_esports_d1_ah_h"]
}
PAGE_URL = "http://eu.battle.net/blizzcon/en/live-stream/"
SUBSCRIPTION_URL ="https://cloudssl.rayv.com/api/SubscriptionProxy/{channels}/"
class Blizzcon(Plugin):
@classmethod
def can_handle_url(self, url):
return "blizzcon://" in url
def _get_streams(self):
match = re.match("blizzcon://(\w+)", self.url)
if not match or not match.group(1) in CHANNELS:
return
channels = CHANNELS[match.group(1)]
res = urlget(PAGE_URL)
params = re.search(r"LiveStream.embedParams\s+=\s+({.+?});", res.text,
re.DOTALL)
if not params:
return
params = re.sub(r"(\w+) :", r'"\1":', params.group(1))
params = re.sub(r": '(.+)'", r': "\1"', params)
params = parse_json(params)
res = urlget(SUBSCRIPTION_URL.format(channels=",".join(channels)),
params=dict(clientToken=params.get("clientToken"),
distributor=params.get("distributor"),
userId=params.get("externalUserId"),
deviceType="", requestId=1383871434184,
ipAddress=params.get("ipAddress"),
password=""))
root = res_xml(res)
streams = {}
for item in root.findall("*/ResponseListItem"):
attr = item.findall("ExtendedDetailsList/*")
attr = dict((a.findtext("Key"), a.findtext("Value"))
for a in attr)
stream = HTTPStream(self.session,
"{0}/{1}".format(attr.get("ConnectionName"),
attr.get("StreamName")),
params=dict(primaryToken=attr.get("Token"),
r="random", g="random",
v="2.5.8", fp="LNX 11,1,102,63"))
stream_name = attr.get("StreamName")
match = re.match(r".+_(\d+)@.+", stream_name)
if match:
stream_name = "{0}k".format(match.group(1))
streams[stream_name] = stream
return streams
__plugin__ = Blizzcon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment