From fe7bd9fc6ba50450e57af6dcd76cfe2400fb5ddc Mon Sep 17 00:00:00 2001 From: intact Date: Mon, 31 Oct 2016 13:18:06 +0100 Subject: [PATCH 1/2] Added plugin for piczel.tv --- docs/plugin_matrix.rst | 1 + src/livestreamer/plugins/piczel.py | 62 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/livestreamer/plugins/piczel.py diff --git a/docs/plugin_matrix.rst b/docs/plugin_matrix.rst index a186d2eb..33101841 100755 --- a/docs/plugin_matrix.rst +++ b/docs/plugin_matrix.rst @@ -63,6 +63,7 @@ nrk - tv.nrk.no Yes Yes Streams may be geo-restrict oldlivestream original.liv... [3]_ Yes No Only mobile streams are supported. periscope periscope.tv Yes Yes Replay/VOD is supported. picarto picarto.tv Yes -- +piczel piczel.tv Yes -- rtve rtve.es Yes No ruv ruv.is Yes Yes Streams may be geo-restricted to Iceland. sbsdiscovery - kanal5play.se -- Yes diff --git a/src/livestreamer/plugins/piczel.py b/src/livestreamer/plugins/piczel.py new file mode 100644 index 00000000..93189f31 --- /dev/null +++ b/src/livestreamer/plugins/piczel.py @@ -0,0 +1,62 @@ +import re + +from livestreamer.plugin import Plugin +from livestreamer.plugin.api import http, validate +from livestreamer.stream import RTMPStream, HLSStream + +STREAMS_URL = "https://piczel.tv:3000/streams/{0}?&page=1&sfw=false&live_only=true" +HLS_URL = "https://5810b93fdf674.streamlock.net:1936/live/{0}/playlist.m3u8" +RTMP_URL = "rtmp://piczel.tv:1935/live/{0}" + +_url_re = re.compile("https://piczel.tv/watch/(\w+)") + +_streams_schema = validate.Schema( + { + "type": validate.text, + "data": [ + { + "id": int, + "live": bool + } + ] + } +) + +class Piczel(Plugin): + @classmethod + def can_handle_url(cls, url): + return _url_re.match(url) + + def _get_streams(self): + match = _url_re.match(self.url) + if not match: + return + + res = http.get(STREAMS_URL.format(match.group(1))) + streams = http.json(res, schema=_streams_schema) + if streams["type"] != "stream": + return + + stream_info = streams["data"][0] + if not stream_info["live"]: + return + + streams = {} + + try: + streams.update(HLSStream.parse_variant_playlist(self.session, HLS_URL.format(stream_info["id"]))) + except IOError as e: + # fix for hosted offline streams + if "404 Client Error" in str(e): + return + raise + + streams["rtmp"] = RTMPStream(self.session, { + "rtmp": RTMP_URL.format(stream_info["id"]), + "pageUrl": self.url, + "live": True + }) + + return streams + +__plugin__ = Piczel From 389e3548e3130ba5ff690508f2bc4c4e19bebe69 Mon Sep 17 00:00:00 2001 From: intact Date: Mon, 31 Oct 2016 20:23:47 +0100 Subject: [PATCH 2/2] plugin.piczel: Fix multi streams --- src/livestreamer/plugins/piczel.py | 48 +++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/livestreamer/plugins/piczel.py b/src/livestreamer/plugins/piczel.py index 93189f31..af411a3f 100644 --- a/src/livestreamer/plugins/piczel.py +++ b/src/livestreamer/plugins/piczel.py @@ -16,7 +16,8 @@ "data": [ { "id": int, - "live": bool + "live": bool, + "slug": validate.text } ] } @@ -32,31 +33,38 @@ def _get_streams(self): if not match: return - res = http.get(STREAMS_URL.format(match.group(1))) - streams = http.json(res, schema=_streams_schema) - if streams["type"] != "stream": - return + channel_name = match.group(1) - stream_info = streams["data"][0] - if not stream_info["live"]: + res = http.get(STREAMS_URL.format(channel_name)) + streams = http.json(res, schema=_streams_schema) + if streams["type"] not in ("multi", "stream"): return - streams = {} + for stream in streams["data"]: + if stream["slug"] != channel_name: + continue - try: - streams.update(HLSStream.parse_variant_playlist(self.session, HLS_URL.format(stream_info["id"]))) - except IOError as e: - # fix for hosted offline streams - if "404 Client Error" in str(e): + if not stream["live"]: return - raise - streams["rtmp"] = RTMPStream(self.session, { - "rtmp": RTMP_URL.format(stream_info["id"]), - "pageUrl": self.url, - "live": True - }) + streams = {} + + try: + streams.update(HLSStream.parse_variant_playlist(self.session, HLS_URL.format(stream["id"]))) + except IOError as e: + # fix for hosted offline streams + if "404 Client Error" in str(e): + return + raise + + streams["rtmp"] = RTMPStream(self.session, { + "rtmp": RTMP_URL.format(stream["id"]), + "pageUrl": self.url, + "live": True + }) + + return streams - return streams + return __plugin__ = Piczel