Skip to content

Commit

Permalink
Merge pull request #686 from daslicious/Fix_mlg_config.json
Browse files Browse the repository at this point in the history
Fix config.json 404 for some channels.
  • Loading branch information
chrippa committed Jan 15, 2015
2 parents d383814 + bfb638f commit 6c05a96
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/livestreamer/plugins/mlgtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
from livestreamer.stream import HDSStream, HLSStream

CONFIG_API_URL = "http://www.majorleaguegaming.com/player/config.json"
PLAYER_EMBED_URL = "http://www.majorleaguegaming.com/player/embed/{0}"
STREAM_API_URL = "http://streamapi.majorleaguegaming.com/service/streams/playback/{0}"
STREAM_TYPES = {
"hls": HLSStream.parse_variant_playlist,
"hds": HDSStream.parse_manifest
}

_stream_id_re = re.compile(r"<meta content='.+/([\w_-]+).+' property='og:video'>")
_player_id_re = re.compile(r"<input type=\"hidden\" id=\"player-id\" value=\"(.+)\" />")
_url_re = re.compile("http(s)?://(\w+\.)?(majorleaguegaming\.com|mlg\.tv)")

_config_schema = validate.Schema(
Expand Down Expand Up @@ -49,6 +51,11 @@ def _find_channel_id(self, text):
if match:
return match.group(1)

def _find_player_id(self, text):
match = _player_id_re.search(text)
if match:
return match.group(1)

def _get_stream_id(self, channel_id):
res = http.get(CONFIG_API_URL, params=dict(id=channel_id))
config = http.json(res, schema=_config_schema)
Expand All @@ -62,7 +69,12 @@ def _get_streams(self):
if not channel_id:
return

stream_id = self._get_stream_id(channel_id)
res = http.get(PLAYER_EMBED_URL.format(channel_id))
player_id = self._find_player_id(res.text)
if not player_id:
return

stream_id = self._get_stream_id(player_id)
if not stream_id:
return

Expand Down

0 comments on commit 6c05a96

Please sign in to comment.