aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Christopher Rosell <chrippa@tanuki.se>2012-06-18 13:59:01 +0200
committerGravatar Christopher Rosell <chrippa@tanuki.se>2012-06-18 13:59:01 +0200
commit48be679ec6cd31208c66e1d93cef213b0e44fce2 (patch)
tree1ac1f0bb09f852b6ce22089c476326c3985fc041
parentac0d0d22ebac4ff5aad69fb89a1414d316aeed8a (diff)
Add SVTPlay plugin.
-rw-r--r--README.md1
-rw-r--r--src/livestreamer/plugins/__init__.py4
-rw-r--r--src/livestreamer/plugins/svtplay.py63
3 files changed, 66 insertions, 2 deletions
diff --git a/README.md b/README.md
index 603e476..c2b2f8d 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,7 @@ Currently supported sites are:
* Justin.tv/Twitch.tv
* Own3D.tv
+* SVTPlay
* UStream
* YouTube
diff --git a/src/livestreamer/plugins/__init__.py b/src/livestreamer/plugins/__init__.py
index 7804a3c..c2f9d80 100644
--- a/src/livestreamer/plugins/__init__.py
+++ b/src/livestreamer/plugins/__init__.py
@@ -15,8 +15,8 @@ class Plugin(object):
raise NotImplementedError
def get_streams(self):
- ranking = ["iphonelow", "iphonehigh", "240p", "360p", "480p", "720p",
- "hd", "1080p", "live"]
+ ranking = ["iphonelow", "iphonehigh", "240p", "320k", "360p", "850k",
+ "480p", "1400k", "720p", "2400k", "hd", "1080p", "live"]
streams = self._get_streams()
for rank in reversed(ranking):
if rank in streams:
diff --git a/src/livestreamer/plugins/svtplay.py b/src/livestreamer/plugins/svtplay.py
new file mode 100644
index 0000000..5757ac1
--- /dev/null
+++ b/src/livestreamer/plugins/svtplay.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+from livestreamer.compat import str
+from livestreamer.plugins import Plugin, PluginError, NoStreamsError, register_plugin
+from livestreamer.stream import RTMPStream
+from livestreamer.utils import urlget, swfverify
+
+import json, re
+
+
+class SVTPlay(Plugin):
+ JSONURL = "http://svtplay.se/live/{0}?output=json"
+ SWFURL = "http://www.svtplay.se/public/swf/video/svtplayer-2012.15.swf"
+ PageURL = "http://www.svtplay.se"
+
+ @classmethod
+ def can_handle_url(self, url):
+ return "svtplay.se" in url
+
+ def _get_channel_id(self, url):
+ data = urlget(url)
+
+ match = re.search(b'data-json-href="/live/(\d+)"', data)
+ if match:
+ return int(match.group(1))
+
+ def _get_streams(self):
+ channelid = self._get_channel_id(self.url)
+
+ if not channelid:
+ raise NoStreamsError(self.url)
+
+ data = urlget(self.JSONURL.format(channelid))
+
+ try:
+ info = json.loads(str(data, "utf8"))
+ except ValueError as err:
+ raise PluginError(("Unable to parse JSON: {0})").format(err))
+
+ if not ("video" in info and "videoReferences" in info["video"]):
+ raise PluginError("Missing 'video' or 'videoReferences' key in JSON")
+
+ streams = {}
+ videos = info["video"]["videoReferences"]
+ swfhash, swfsize = swfverify(self.SWFURL)
+
+ for video in videos:
+ if not ("url" in video and "playerType" in video and video["playerType"] == "flash"):
+ continue
+
+ stream = RTMPStream({
+ "rtmp": video["url"],
+ "pageUrl": self.PageURL,
+ "swfhash": swfhash,
+ "swfsize": swfsize,
+ "live": True
+ })
+ streams[str(video["bitrate"]) + "k"] = stream
+
+
+ return streams
+
+register_plugin("svtplay", SVTPlay)