Created
October 30, 2015 22:29
-
-
Save intact/21784f84566275d2bb53 to your computer and use it in GitHub Desktop.
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 re | |
from livestreamer.plugin import Plugin | |
from livestreamer.plugin.api import http, validate | |
from livestreamer.plugin.api.utils import parse_json | |
from livestreamer.stream import ( | |
HTTPStream, HLSStream | |
) | |
STATUS_ONLINE = 4 | |
STATUS_OFFLINE = 0 | |
_url_re = re.compile(""" | |
http(s)?://(www\.)?zhanqi.tv | |
/(?P<channel>[^/]+) | |
""", re.VERBOSE) | |
_json_re = re.compile(r"window\.oPageConfig\.oRoom\s=\s({.+?});") | |
_room_schema = validate.Schema( | |
validate.all( | |
validate.transform(_json_re.search), | |
validate.any( | |
None, | |
validate.all( | |
validate.get(1), | |
validate.transform(parse_json), | |
{ | |
"status": validate.all( | |
validate.text, | |
validate.transform(int) | |
), | |
"videoId": validate.text | |
} | |
) | |
) | |
) | |
) | |
class Zhanqi(Plugin): | |
@classmethod | |
def can_handle_url(self, url): | |
return _url_re.match(url) | |
def _get_streams(self): | |
match = _url_re.match(self.url) | |
channel = match.group("channel") | |
room = http.get(self.url, schema=_room_schema) | |
if not room: | |
return | |
if room["status"] != STATUS_ONLINE: | |
return | |
hls_url = "http://dlhls.cdn.zhanqi.tv/zqlive/{room[videoId]}.m3u8".format(room=room) | |
return HLSStream.parse_variant_playlist(self.session, hls_url) | |
__plugin__ = Zhanqi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment