From ae9d8dfad33e9299332534f12b074c1482f6aeb5 Mon Sep 17 00:00:00 2001 From: blxd Date: Fri, 13 Mar 2015 15:44:11 +0000 Subject: [PATCH 1/2] Added plugin for the Catalan TV site tv3.cat --- docs/plugin_matrix.rst | 1 + src/livestreamer/plugins/tv3cat.py | 59 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/livestreamer/plugins/tv3cat.py diff --git a/docs/plugin_matrix.rst b/docs/plugin_matrix.rst index 175872da..0f6be023 100644 --- a/docs/plugin_matrix.rst +++ b/docs/plugin_matrix.rst @@ -65,6 +65,7 @@ svtplay - svtplay.se Yes Yes Streams may be geo-restrict - oppetarkiv.se tga - star.plu.cn Yes No - star.tga.plu.cn +tv3cat tv3.cat Yes Yes Streams may be geo-restricted to Spain. tv4play - tv4play.se Yes Yes Streams may be geo-restricted to Sweden. Only non-premium streams currently supported. - fotbollskanalen.se diff --git a/src/livestreamer/plugins/tv3cat.py b/src/livestreamer/plugins/tv3cat.py new file mode 100644 index 00000000..1aa90f76 --- /dev/null +++ b/src/livestreamer/plugins/tv3cat.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +import re +import logging + +from livestreamer.plugin import Plugin +from livestreamer.plugin.api import http +from livestreamer.stream import HLSStream +from livestreamer.plugin.api import validate + + +log = logging.getLogger(__name__) + +STREAM_INFO_URL = "http://dinamics.ccma.cat/pvideo/media.jsp?media=video&version=0s&idint={ident}&profile=pc&desplacament=0" +_url_re = re.compile(r"http://(?:www.)?ccma.cat/tv3/directe/(.+?)/") +_channel_schema = validate.Schema({ + "media": validate.any([{ + "geo": validate.text, + "url": validate.url(scheme=validate.any("http")) + }], + { + "geo": validate.text, + "url": validate.url(scheme=validate.any("http")) + }) +}) + + +class TV3Cat(Plugin): + @classmethod + def can_handle_url(self, url): + match = _url_re.match(url) + return match + + def _get_streams(self): + + match = _url_re.match(self.url) + if match: + ident = match.group(1) + data_url = STREAM_INFO_URL.format(ident=ident) + + # find the region, default to TOTS (international) + res = http.get(self.url) + geo_data = re.search(r'data-geo="([A-Z]+?)"', res.text) + geo = geo_data and geo_data.group(1) or "TOTS" + + stream_data = http.json(http.get(data_url), schema=_channel_schema) + + # If there is only one item, it's not a list ... silly + if isinstance(stream_data['media'], list): + stream_infos = stream_data['media'] + else: + stream_infos = [stream_data['media']] + + for stream in stream_infos: + if stream['geo'] == geo: + return HLSStream.parse_variant_playlist(self.session, stream['url']) + + +__plugin__ = TV3Cat + From 4a526fdf14987d5a5cf2f4910b00c0bc17637c54 Mon Sep 17 00:00:00 2001 From: blxd Date: Mon, 16 Mar 2015 11:23:54 +0000 Subject: [PATCH 2/2] removed duplication in channel schema --- src/livestreamer/plugins/tv3cat.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/livestreamer/plugins/tv3cat.py b/src/livestreamer/plugins/tv3cat.py index 1aa90f76..d1100cc6 100644 --- a/src/livestreamer/plugins/tv3cat.py +++ b/src/livestreamer/plugins/tv3cat.py @@ -1,27 +1,20 @@ #!/usr/bin/env python import re -import logging from livestreamer.plugin import Plugin from livestreamer.plugin.api import http from livestreamer.stream import HLSStream from livestreamer.plugin.api import validate - -log = logging.getLogger(__name__) - STREAM_INFO_URL = "http://dinamics.ccma.cat/pvideo/media.jsp?media=video&version=0s&idint={ident}&profile=pc&desplacament=0" _url_re = re.compile(r"http://(?:www.)?ccma.cat/tv3/directe/(.+?)/") -_channel_schema = validate.Schema({ - "media": validate.any([{ - "geo": validate.text, - "url": validate.url(scheme=validate.any("http")) - }], - { +_media_schema = validate.Schema({ "geo": validate.text, "url": validate.url(scheme=validate.any("http")) }) -}) +_channel_schema = validate.Schema({ + "media": validate.any([_media_schema], _media_schema) + }) class TV3Cat(Plugin):