1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-25 12:45:42 +01:00
svtplay-dl/lib/svtplay_dl/service/dr.py

74 lines
2.8 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 json
2013-12-30 01:39:05 +01:00
import sys
2014-01-26 01:51:53 +01:00
from svtplay_dl.service import Service, OpenGraphThumbMixin
from svtplay_dl.utils import get_http_data, select_quality
from svtplay_dl.fetcher.rtmp import download_rtmp
2013-09-14 22:13:34 +02:00
from svtplay_dl.fetcher.hls import download_hls
2013-12-30 01:39:05 +01:00
from svtplay_dl.log import log
2014-01-26 01:51:53 +01:00
class Dr(Service, OpenGraphThumbMixin):
supported_domains = ['dr.dk']
2014-01-06 23:14:06 +01:00
def get(self, options):
data = self.get_urldata()
match = re.search(r'resource:[ ]*"([^"]*)",', data)
2013-09-14 22:39:37 +02:00
if match:
resource_url = match.group(1)
resource_data = get_http_data(resource_url)
resource = json.loads(resource_data)
tempresource = resource['Data'][0]['Assets']
# To find the VideoResource, they have Images as well
for resources in tempresource:
if resources['Kind'] == 'VideoResource':
links = resources['Links']
break
2013-09-14 21:58:55 +02:00
2013-09-14 22:39:37 +02:00
streams = {}
for i in links:
if options.hls:
if i["Target"] == "Ios":
stream = {}
stream["uri"] = i["Uri"]
streams[int(i["Bitrate"])] = stream
else:
if i["Target"] == "Streaming":
stream = {}
stream["uri"] = i["Uri"]
streams[int(i["Bitrate"])] = stream
if len(streams) == 1:
test = streams[list(streams.keys())[0]]
2013-09-14 22:13:34 +02:00
else:
2013-09-14 22:39:37 +02:00
test = select_quality(options, streams)
2013-09-14 21:58:55 +02:00
2013-09-14 22:39:37 +02:00
if options.hls:
2014-02-08 16:08:39 +01:00
download_hls(options, test["uri"])
2013-09-14 22:39:37 +02:00
else:
options.other = "-y '%s'" % test["uri"].replace("rtmp://vod.dr.dk/cms/", "")
rtmp = "rtmp://vod.dr.dk/cms/"
download_rtmp(options, rtmp)
2013-09-14 21:58:55 +02:00
else:
2013-09-14 22:39:37 +02:00
match = re.search(r'resource="([^"]*)"', data)
if not match:
log.error("Cant find resource info for this video")
sys.exit(2)
resource_url = "http://www.dr.dk%s" % match.group(1)
resource_data = get_http_data(resource_url)
resource = json.loads(resource_data)
streams = {}
for stream in resource['links']:
streams[stream['bitrateKbps']] = stream['uri']
if len(streams) == 1:
uri = streams[list(streams.keys())[0]]
else:
uri = select_quality(options, streams)
2013-09-14 21:58:55 +02:00
2013-09-14 22:39:37 +02:00
options.other = "-v -y '" + uri.replace("rtmp://vod.dr.dk/cms/", "") + "'"
2013-09-14 22:13:34 +02:00
rtmp = "rtmp://vod.dr.dk/cms/"
download_rtmp(options, rtmp)