Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added plugin for the Catalan TV site tv3.cat #784

Merged
merged 2 commits into from
Mar 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/plugin_matrix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions src/livestreamer/plugins/tv3cat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
import re

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

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/(.+?)/")
_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)
})

Copy link
Owner

Choose a reason for hiding this comment

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

To avoid repeating yourself you can reference schemas in schemas, e.g.

_media_schema = validate.Schema({
    "geo": validate.text,
    "url": validate.url(scheme="http")
})
_channel_schema = validate.Schema({
    "media": validate.any([_media_schema], _media_schema)
})


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