Skip to content

Commit

Permalink
Fix config.json 404 for some channels. Use embed url to retrieve corr…
Browse files Browse the repository at this point in the history
…ect config parameter. Closes chrippa#683 Closes chrippa#685
  • Loading branch information
daslicious committed Jan 14, 2015
1 parent 8d655c7 commit bfb638f
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

1 comment on commit bfb638f

@K4DE
Copy link

@K4DE K4DE commented on bfb638f Jan 14, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what do i do to fix the broken streams?

Please sign in to comment.