aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/livestreamer/plugins/svtplay.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/livestreamer/plugins/svtplay.py')
-rw-r--r--src/livestreamer/plugins/svtplay.py54
1 files changed, 24 insertions, 30 deletions
diff --git a/src/livestreamer/plugins/svtplay.py b/src/livestreamer/plugins/svtplay.py
index a3bfa5a..d802b47 100644
--- a/src/livestreamer/plugins/svtplay.py
+++ b/src/livestreamer/plugins/svtplay.py
@@ -1,12 +1,11 @@
from livestreamer.compat import str
from livestreamer.plugins import Plugin, PluginError, NoStreamsError
-from livestreamer.stream import RTMPStream
+from livestreamer.stream import RTMPStream, HLSStream
from livestreamer.utils import urlget, swfverify, verifyjson
import re
class SVTPlay(Plugin):
- JSONURL = "http://svtplay.se/live/{0}"
SWFURL = "http://www.svtplay.se/public/swf/video/svtplayer-2012.15.swf"
PageURL = "http://www.svtplay.se"
@@ -14,24 +13,9 @@ class SVTPlay(Plugin):
def can_handle_url(self, url):
return "svtplay.se" in url
- def _get_channel_id(self, url):
- self.logger.debug("Fetching channel id")
-
- res = urlget(url)
-
-
- match = re.search('data-json-href="/live/(\d+)"', res.text)
- 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)
-
self.logger.debug("Fetching stream info")
- res = urlget(self.JSONURL.format(channelid), params=dict(output="json"))
+ res = urlget(self.url, params=dict(output="json"))
if res.json is None:
raise PluginError("No JSON data in stream info")
@@ -39,22 +23,32 @@ class SVTPlay(Plugin):
streams = {}
video = verifyjson(res.json, "video")
videos = verifyjson(video, "videoReferences")
-
- self.logger.debug("Verifying SWF: {0}", self.SWFURL)
- swfhash, swfsize = swfverify(self.SWFURL)
+ swfhash, swfsize = (None, None)
for video in videos:
- if not ("url" in video and "playerType" in video and video["playerType"] == "flash"):
+ if not ("url" in video and "playerType" in video):
continue
- stream = RTMPStream(self.session, {
- "rtmp": video["url"],
- "pageUrl": self.PageURL,
- "swfhash": swfhash,
- "swfsize": swfsize,
- "live": True
- })
- streams[str(video["bitrate"]) + "k"] = stream
+ if video["playerType"] == "flash":
+ if video["url"].startswith("rtmp"):
+ if not swfhash:
+ self.logger.debug("Verifying SWF: {0}", self.SWFURL)
+ swfhash, swfsize = swfverify(self.SWFURL)
+
+ stream = RTMPStream(self.session, {
+ "rtmp": video["url"],
+ "pageUrl": self.PageURL,
+ "swfhash": swfhash,
+ "swfsize": swfsize,
+ "live": True
+ })
+ streams[str(video["bitrate"]) + "k"] = stream
+ elif video["playerType"] == "ios":
+ try:
+ hlsstreams = HLSStream.parse_variant_playlist(self.session, video["url"])
+ streams.update(hlsstreams)
+ except IOError as err:
+ self.logger.warning("Failed to get variant playlist: {0}", err)
return streams