1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 06:04:17 +01:00
svtplay-dl/lib/svtplay_dl/service/qbrick.py

82 lines
3.2 KiB
Python
Raw Normal View History

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 -*-
from __future__ import absolute_import
import re
import copy
import xml.etree.ElementTree as ET
2014-01-26 01:19:47 +01:00
from svtplay_dl.service import Service, OpenGraphThumbMixin
2014-12-08 23:07:02 +01:00
from svtplay_dl.utils import get_http_data, is_py2_old
2014-03-09 16:26:45 +01:00
from svtplay_dl.utils.urllib import unquote_plus
from svtplay_dl.log import log
2014-04-21 18:24:26 +02:00
from svtplay_dl.fetcher.rtmp import RTMP
2014-01-26 01:19:47 +01:00
class Qbrick(Service, OpenGraphThumbMixin):
supported_domains = ['di.se', 'sydsvenskan.se']
2014-01-06 23:14:06 +01:00
def get(self, options):
2014-12-08 23:07:02 +01:00
error, data = self.get_urldata()
if error:
2014-11-26 16:00:11 +01:00
log.error("Can't get the page")
return
if self.exclude(options):
return
2014-11-26 16:00:11 +01:00
if re.findall(r"sydsvenskan.se", self.url):
match = re.search(r"data-qbrick-mcid=\"([0-9A-F]+)\"", data)
if not match:
2014-10-06 23:21:43 +02:00
log.error("Can't find video file for: %s", self.url)
return
2013-05-03 16:59:40 +02:00
mcid = match.group(1)
host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % mcid
2014-01-06 23:14:06 +01:00
elif re.findall(r"di.se", self.url):
match = re.search("src=\"(http://qstream.*)\"></iframe", data)
if not match:
2014-10-06 23:21:43 +02:00
log.error("Can't find video info for: %s", self.url)
return
2014-12-08 23:07:02 +01:00
error, data = get_http_data(match.group(1))
match = re.search(r"data-qbrick-ccid=\"([0-9A-Z]+)\"", data)
if not match:
2014-10-06 23:21:43 +02:00
log.error("Can't find video file for: %s", self.url)
return
host = "http://vms.api.qbrick.com/rest/v3/getplayer/%s" % match.group(1)
2014-01-06 23:14:06 +01:00
elif re.findall(r"svd.se", self.url):
2014-12-08 23:07:02 +01:00
match = re.search(r'video url-([^"]*)\"', self.get_urldata()[1])
if not match:
2014-10-06 23:21:43 +02:00
log.error("Can't find video file for: %s", self.url)
return
2014-03-09 16:26:45 +01:00
path = unquote_plus(match.group(1))
2014-12-08 23:07:02 +01:00
error, data = get_http_data("http://www.svd.se%s" % path)
match = re.search(r"mcid=([A-F0-9]+)\&width=", data)
if not match:
2014-10-06 23:21:43 +02:00
log.error("Can't find video file for: %s", self.url)
return
host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % match.group(1)
else:
2014-10-06 23:21:43 +02:00
log.error("Can't find any info for %s", self.url)
return
2014-12-08 23:07:02 +01:00
error, 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")
2014-10-06 23:21:43 +02:00
return
live = xml.find("media").find("item").find("playlist").find("stream").attrib["isLive"]
if live == "true":
options.live = True
2014-12-08 23:07:02 +01:00
error, 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:
sa = list(streams.getiterator("video"))
else:
sa = list(streams.iter("video"))
2014-04-21 18:24:26 +02:00
for i in sa:
options.other = "-y '%s'" % i.attrib["src"]
2014-06-07 20:43:40 +02:00
yield RTMP(copy.copy(options), server, i.attrib["system-bitrate"])