Skip to content

Commit

Permalink
Merge pull request #466 from eltiren/develop
Browse files Browse the repository at this point in the history
Added GoodGame.ru portal plugin
  • Loading branch information
chrippa committed Aug 2, 2014
2 parents 8e3bad2 + 1699e41 commit e480c83
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/livestreamer/plugins/goodgame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import re

from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http
from livestreamer.stream import HLSStream

HLS_URL_FORMAT = "http://hls.goodgame.ru/hls/{0}{1}.m3u8"
QUALITIES = {
"1080p": "",
"720p": "_720",
"480p": "_480",
"240p": "_240"
}

_url_re = re.compile("http://(?:www\.)?goodgame.ru/channel/(?P<user>\w+)/")
_stream_re = re.compile(
"\s+data-objid=\"(\d+)\" id=\"channel-popup-link\" class=\"fright font-size-small\">"
)

class GoodGame(Plugin):
@classmethod
def can_handle_url(self, url):
return _url_re.match(url)

def _check_stream(self, url):
res = http.get(url, acceptable_status=(200, 404))
if res.status_code == 200:
return True

def _get_streams(self):
res = http.get(self.url)
match = _stream_re.search(res.text)
if not match:
return

stream_id = match.group(1)
streams = {}
for name, url_suffix in QUALITIES.items():
url = HLS_URL_FORMAT.format(stream_id, url_suffix)
if not self._check_stream(url):
continue

streams[name] = HLSStream(self.session, url)

return streams

__plugin__ = GoodGame

0 comments on commit e480c83

Please sign in to comment.