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-02-12 19:43:37 +01:00
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
2013-04-21 12:44:31 +02:00
|
|
|
from svtplay_dl.service import Service
|
2013-12-30 01:35:08 +01:00
|
|
|
from svtplay_dl.utils import get_http_data, select_quality, is_py2_old
|
2013-03-17 19:55:19 +01:00
|
|
|
from svtplay_dl.log import log
|
|
|
|
from svtplay_dl.fetcher.rtmp import download_rtmp
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2013-04-21 12:44:31 +02:00
|
|
|
class Qbrick(Service):
|
2014-01-01 14:57:17 +01:00
|
|
|
supported_domains = ['dn.se', 'di.se', 'svd.se', 'sydsvenskan.se']
|
2013-01-17 00:21:47 +01:00
|
|
|
|
|
|
|
def get(self, options, url):
|
2013-09-04 14:59:21 +02:00
|
|
|
if re.findall(r"sydsvenskan.se", url):
|
2013-01-17 00:21:47 +01:00
|
|
|
data = get_http_data(url)
|
2013-05-05 12:57:42 +02:00
|
|
|
match = re.search(r"data-qbrick-mcid=\"([0-9A-F]+)\"", data)
|
2013-01-17 00:21:47 +01:00
|
|
|
if not match:
|
2013-05-03 16:59:40 +02:00
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
|
|
|
mcid = match.group(1)
|
2013-01-17 00:21:47 +01:00
|
|
|
host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % mcid
|
2013-05-05 12:57:42 +02:00
|
|
|
elif re.findall(r"di.se", url):
|
2013-01-17 00:21:47 +01:00
|
|
|
data = get_http_data(url)
|
2013-04-29 14:33:36 +02:00
|
|
|
match = re.search("src=\"(http://qstream.*)\"></iframe", data)
|
|
|
|
if not match:
|
|
|
|
log.error("Can't find video info")
|
|
|
|
sys.exit(2)
|
|
|
|
data = get_http_data(match.group(1))
|
2013-05-05 12:57:42 +02:00
|
|
|
match = re.search(r"data-qbrick-ccid=\"([0-9A-Z]+)\"", data)
|
2013-01-17 00:21:47 +01:00
|
|
|
if not match:
|
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
|
|
|
host = "http://vms.api.qbrick.com/rest/v3/getplayer/%s" % match.group(1)
|
2013-09-04 14:59:21 +02:00
|
|
|
elif re.findall(r"dn.se", url):
|
|
|
|
data = get_http_data(url)
|
|
|
|
match = re.search(r"'([0-9A-F]{8})',", data)
|
|
|
|
if not match:
|
|
|
|
match = re.search(r"mediaId = '([0-9A-F]{8})';", data)
|
|
|
|
if not match:
|
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
|
|
|
host = "http://vms.api.qbrick.com/rest/v3//getsingleplayer/%sDE1BA107?statusCode=xml" % match.group(1)
|
2013-05-05 12:57:42 +02:00
|
|
|
elif re.findall(r"svd.se", url):
|
|
|
|
match = re.search(r"_([0-9]+)\.svd", url)
|
2013-01-17 00:21:47 +01:00
|
|
|
if not match:
|
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
|
|
|
data = get_http_data("http://www.svd.se/?service=ajax&type=webTvClip&articleId=%s" % match.group(1))
|
2013-05-05 12:57:42 +02:00
|
|
|
match = re.search(r"mcid=([A-F0-9]+)\&width=", data)
|
2013-01-17 00:21:47 +01:00
|
|
|
if not match:
|
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
|
|
|
host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % match.group(1)
|
|
|
|
else:
|
|
|
|
log.error("Can't find site")
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
data = get_http_data(host)
|
|
|
|
xml = ET.XML(data)
|
|
|
|
try:
|
|
|
|
url = xml.find("media").find("item").find("playlist").find("stream").find("format").find("substream").text
|
|
|
|
except AttributeError:
|
|
|
|
log.error("Can't find video file")
|
|
|
|
sys.exit(2)
|
2013-09-04 14:59:52 +02:00
|
|
|
live = xml.find("media").find("item").find("playlist").find("stream").attrib["isLive"]
|
|
|
|
if live == "true":
|
|
|
|
options.live = True
|
2013-01-17 00:21:47 +01:00
|
|
|
data = get_http_data(url)
|
|
|
|
xml = ET.XML(data)
|
|
|
|
server = xml.find("head").find("meta").attrib["base"]
|
|
|
|
streams = xml.find("body").find("switch")
|
2013-12-30 01:35:08 +01:00
|
|
|
if is_py2_old:
|
2013-01-17 00:21:47 +01:00
|
|
|
sa = list(streams.getiterator("video"))
|
|
|
|
else:
|
|
|
|
sa = list(streams.iter("video"))
|
|
|
|
streams = {}
|
|
|
|
for i in sa:
|
|
|
|
streams[int(i.attrib["system-bitrate"])] = i.attrib["src"]
|
|
|
|
|
|
|
|
path = select_quality(options, streams)
|
|
|
|
|
|
|
|
options.other = "-y %s" % path
|
|
|
|
download_rtmp(options, server)
|
|
|
|
|