2013-03-02 21:26:28 +01:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2013-03-01 23:39:42 +01:00
|
|
|
from __future__ import absolute_import
|
2013-01-17 00:21:47 +01:00
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import json
|
|
|
|
|
2014-01-19 14:26:48 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2013-03-24 20:24:08 +01:00
|
|
|
from svtplay_dl.utils import get_http_data, select_quality, subtitle_wsrt
|
2013-10-14 20:05:03 +02:00
|
|
|
from svtplay_dl.utils.urllib import urlparse
|
2013-03-17 19:55:19 +01:00
|
|
|
from svtplay_dl.fetcher.hds import download_hds
|
|
|
|
from svtplay_dl.fetcher.hls import download_hls
|
|
|
|
from svtplay_dl.fetcher.rtmp import download_rtmp
|
|
|
|
from svtplay_dl.fetcher.http import download_http
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2013-03-17 19:55:19 +01:00
|
|
|
from svtplay_dl.log import log
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-01-19 14:26:48 +01:00
|
|
|
class Svtplay(Service, OpenGraphThumbMixin):
|
2014-01-16 12:33:54 +01:00
|
|
|
supported_domains = ['svtplay.se', 'svt.se', 'oppetarkiv.se', 'beta.svtplay.se']
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-01-11 23:02:47 +01:00
|
|
|
def __init__(self, url):
|
|
|
|
Service.__init__(self, url)
|
|
|
|
self.subtitle = None
|
|
|
|
|
2014-01-06 23:14:06 +01:00
|
|
|
def get(self, options):
|
|
|
|
if re.findall("svt.se", self.url):
|
2014-02-18 16:48:53 +01:00
|
|
|
match = re.search(r"data-json-href=\"(.*)\"", self.get_urldata())
|
2013-01-17 00:21:47 +01:00
|
|
|
if match:
|
|
|
|
filename = match.group(1).replace("&", "&").replace("&format=json", "")
|
|
|
|
url = "http://www.svt.se%s" % filename
|
|
|
|
else:
|
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
2014-01-06 23:14:06 +01:00
|
|
|
else:
|
|
|
|
url = self.url
|
2013-04-21 12:29:16 +02:00
|
|
|
|
2013-11-14 22:46:08 +01:00
|
|
|
pos = url.find("?")
|
|
|
|
if pos < 0:
|
|
|
|
dataurl = "%s?&output=json&format=json" % url
|
|
|
|
else:
|
|
|
|
dataurl = "%s&output=json&format=json" % url
|
|
|
|
data = json.loads(get_http_data(dataurl))
|
2013-04-16 13:18:40 +02:00
|
|
|
if "live" in data["video"]:
|
|
|
|
options.live = data["video"]["live"]
|
|
|
|
else:
|
|
|
|
options.live = False
|
2014-01-11 23:02:47 +01:00
|
|
|
|
2014-02-11 18:16:26 +01:00
|
|
|
if data["video"]["subtitleReferences"]:
|
|
|
|
try:
|
|
|
|
self.subtitle = data["video"]["subtitleReferences"][0]["url"]
|
|
|
|
except (KeyError, NoneType):
|
|
|
|
pass
|
2014-01-11 23:02:47 +01:00
|
|
|
|
2013-01-17 00:21:47 +01:00
|
|
|
streams = {}
|
|
|
|
streams2 = {} #hack..
|
|
|
|
for i in data["video"]["videoReferences"]:
|
2013-10-14 20:05:03 +02:00
|
|
|
parse = urlparse(i["url"])
|
|
|
|
if options.hls and parse.path[len(parse.path)-4:] == "m3u8":
|
2013-01-17 00:21:47 +01:00
|
|
|
stream = {}
|
|
|
|
stream["url"] = i["url"]
|
|
|
|
streams[int(i["bitrate"])] = stream
|
2013-10-14 20:05:03 +02:00
|
|
|
elif not options.hls and parse.path[len(parse.path)-3:] == "f4m":
|
2013-01-17 00:21:47 +01:00
|
|
|
stream = {}
|
|
|
|
stream["url"] = i["url"]
|
|
|
|
streams[int(i["bitrate"])] = stream
|
2013-10-21 14:01:52 +02:00
|
|
|
elif not options.hls and parse.path[len(parse.path)-3:] != "f4m" and parse.path[len(parse.path)-4:] != "m3u8":
|
2013-10-08 15:27:00 +02:00
|
|
|
stream = {}
|
|
|
|
stream["url"] = i["url"]
|
|
|
|
streams[int(i["bitrate"])] = stream
|
2013-10-14 20:05:03 +02:00
|
|
|
if options.hls and parse.path[len(parse.path)-3:] == "f4m":
|
2013-01-17 00:21:47 +01:00
|
|
|
stream = {}
|
|
|
|
stream["url"] = i["url"]
|
|
|
|
streams2[int(i["bitrate"])] = stream
|
|
|
|
|
|
|
|
if len(streams) == 0 and options.hls:
|
2013-10-08 15:27:00 +02:00
|
|
|
if len(streams) == 0:
|
|
|
|
log.error("Can't find any streams.")
|
|
|
|
sys.exit(2)
|
2013-02-12 18:49:32 +01:00
|
|
|
test = streams2[0]
|
2013-01-17 00:21:47 +01:00
|
|
|
test["url"] = test["url"].replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8")
|
|
|
|
elif len(streams) == 0:
|
|
|
|
log.error("Can't find any streams.")
|
|
|
|
sys.exit(2)
|
|
|
|
elif len(streams) == 1:
|
|
|
|
test = streams[list(streams.keys())[0]]
|
|
|
|
else:
|
|
|
|
test = select_quality(options, streams)
|
|
|
|
|
2013-10-21 14:01:52 +02:00
|
|
|
parse = urlparse(test["url"])
|
|
|
|
if parse.scheme == "rtmp":
|
2013-11-14 22:44:46 +01:00
|
|
|
embedurl = "%s?type=embed" % url
|
|
|
|
data = get_http_data(embedurl)
|
2013-12-30 01:43:59 +01:00
|
|
|
match = re.search(r"value=\"(/(public)?(statiskt)?/swf(/video)?/svtplayer-[0-9\.a-f]+swf)\"", data)
|
2013-11-14 22:44:46 +01:00
|
|
|
swf = "http://www.svtplay.se%s" % match.group(1)
|
|
|
|
options.other = "-W %s" % swf
|
2013-01-17 00:21:47 +01:00
|
|
|
download_rtmp(options, test["url"])
|
|
|
|
elif options.hls:
|
|
|
|
download_hls(options, test["url"])
|
2013-10-21 14:01:52 +02:00
|
|
|
elif parse.path[len(parse.path)-3:] == "f4m":
|
2013-05-05 12:57:42 +02:00
|
|
|
match = re.search(r"\/se\/secure\/", test["url"])
|
2013-01-17 00:21:47 +01:00
|
|
|
if match:
|
|
|
|
log.error("This stream is encrypted. Use --hls option")
|
|
|
|
sys.exit(2)
|
|
|
|
manifest = "%s?hdcore=2.8.0&g=hejsan" % test["url"]
|
2013-04-21 12:29:16 +02:00
|
|
|
download_hds(options, manifest)
|
2013-01-17 00:21:47 +01:00
|
|
|
else:
|
|
|
|
download_http(options, test["url"])
|
2014-01-11 23:02:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_subtitle(self, options):
|
|
|
|
if self.subtitle:
|
|
|
|
if options.output != "-":
|
|
|
|
data = get_http_data(self.subtitle)
|
|
|
|
subtitle_wsrt(options, data)
|