From 28d0110d44a9a78233dfc829d5510a2c02c264d1 Mon Sep 17 00:00:00 2001 From: Dominik Dabrowski Date: Thu, 19 Apr 2012 18:25:55 +0200 Subject: Putting some organizational logic into the Plugin base class to automatically choose a 'best' quality --- src/livestreamer/plugins/__init__.py | 10 ++++++++++ src/livestreamer/plugins/justintv.py | 2 +- src/livestreamer/plugins/ownedtv.py | 2 +- src/livestreamer/plugins/ustreamtv.py | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/livestreamer/plugins/__init__.py b/src/livestreamer/plugins/__init__.py index cf6954b..a4e39cc 100644 --- a/src/livestreamer/plugins/__init__.py +++ b/src/livestreamer/plugins/__init__.py @@ -23,6 +23,16 @@ class Plugin(object): self.args = args def get_streams(self): + ranking = ['iphonelow', 'iphonehigh', '240p', '360p', '480p', '720p', + 'hd', '1080p', 'live'] + streams = self._get_streams() + for rank in reversed(ranking): + if rank in streams: + streams['best'] = streams[rank] + break + return streams + + def _get_streams(self): raise NotImplementedError def load_plugins(plugins): diff --git a/src/livestreamer/plugins/justintv.py b/src/livestreamer/plugins/justintv.py index b21f9a4..16c522c 100644 --- a/src/livestreamer/plugins/justintv.py +++ b/src/livestreamer/plugins/justintv.py @@ -69,7 +69,7 @@ class JustinTV(Plugin): res.append(node.data) return "".join(res) - def get_streams(self): + def _get_streams(self): def clean_tag(tag): if tag[0] == "_": return tag[1:] diff --git a/src/livestreamer/plugins/ownedtv.py b/src/livestreamer/plugins/ownedtv.py index ab9c479..e2ccf94 100644 --- a/src/livestreamer/plugins/ownedtv.py +++ b/src/livestreamer/plugins/ownedtv.py @@ -46,7 +46,7 @@ class OwnedTV(Plugin): if match: return int(match.group(1)) - def get_streams(self): + def _get_streams(self): channelid = self._get_channel_id(self.url) if not channelid: diff --git a/src/livestreamer/plugins/ustreamtv.py b/src/livestreamer/plugins/ustreamtv.py index 5f120f5..a30e695 100644 --- a/src/livestreamer/plugins/ustreamtv.py +++ b/src/livestreamer/plugins/ustreamtv.py @@ -23,7 +23,7 @@ class UStreamTV(Plugin): if match: return int(match.group(1)) - def get_streams(self): + def _get_streams(self): def get_amf_value(data, key): pattern = ("{0}\W\W\W(.+?)\x00").format(key) match = re.search(bytes(pattern, "ascii"), data) -- cgit v1.2.3