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 re
|
|
|
|
import json
|
2014-06-07 20:43:40 +02:00
|
|
|
import copy
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-26 01:51:53 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2014-04-21 18:26:43 +02:00
|
|
|
from svtplay_dl.fetcher.rtmp import RTMP
|
2014-04-21 21:55:39 +02:00
|
|
|
from svtplay_dl.fetcher.hls import HLS, hlsparse
|
2014-06-02 21:43:22 +02:00
|
|
|
from svtplay_dl.fetcher.hds import hdsparse
|
2015-03-01 21:46:22 +01:00
|
|
|
from svtplay_dl.subtitle import subtitle
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-26 01:51:53 +01:00
|
|
|
class Dr(Service, OpenGraphThumbMixin):
|
2014-01-01 14:57:17 +01:00
|
|
|
supported_domains = ['dr.dk']
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-01-06 23:14:06 +01:00
|
|
|
def get(self, options):
|
2015-08-30 00:06:20 +02:00
|
|
|
data = self.get_urldata()
|
2014-12-22 17:41:40 +01:00
|
|
|
|
|
|
|
if self.exclude(options):
|
|
|
|
return
|
|
|
|
|
2013-01-17 00:21:47 +01:00
|
|
|
match = re.search(r'resource:[ ]*"([^"]*)",', data)
|
2013-09-14 22:39:37 +02:00
|
|
|
if match:
|
|
|
|
resource_url = match.group(1)
|
2015-08-31 19:45:15 +02:00
|
|
|
resource_data = self.http.request("get", resource_url).content
|
2013-09-14 22:39:37 +02:00
|
|
|
resource = json.loads(resource_data)
|
2015-09-01 00:37:06 +02:00
|
|
|
streams = self.find_stream(options, resource)
|
2014-08-11 19:46:56 +02:00
|
|
|
for i in streams:
|
|
|
|
yield i
|
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:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Cant find resource info for this video")
|
2014-10-06 23:21:43 +02:00
|
|
|
return
|
2015-09-01 00:37:06 +02:00
|
|
|
resource_url = "http:%s" % match.group(1)
|
|
|
|
resource_data = self.http.request("get", resource_url).text
|
2013-09-14 22:39:37 +02:00
|
|
|
resource = json.loads(resource_data)
|
2013-09-14 21:58:55 +02:00
|
|
|
|
2015-03-01 21:46:22 +01:00
|
|
|
if "SubtitlesList" in resource:
|
|
|
|
suburl = resource["SubtitlesList"][0]["Uri"]
|
|
|
|
yield subtitle(copy.copy(options), "wrst", suburl)
|
2014-08-11 19:46:56 +02:00
|
|
|
if "Data" in resource:
|
2015-09-01 00:37:06 +02:00
|
|
|
|
|
|
|
streams = self.find_stream(options, resource)
|
2014-08-11 19:46:56 +02:00
|
|
|
for i in streams:
|
|
|
|
yield i
|
|
|
|
else:
|
|
|
|
for stream in resource['Links']:
|
|
|
|
if stream["Target"] == "HDS":
|
2015-08-31 19:45:15 +02:00
|
|
|
streams = hdsparse(copy.copy(options), self.http.request("get", stream["Uri"], params={"hdcore": "3.7.0"}).text, stream["Uri"])
|
2014-10-12 23:31:02 +02:00
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|
2014-08-11 19:46:56 +02:00
|
|
|
if stream["Target"] == "HLS":
|
2015-09-01 00:37:06 +02:00
|
|
|
streams = hlsparse(stream["Uri"], self.http.request("get", stream["Uri"]).text)
|
2014-08-11 19:46:56 +02:00
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield HLS(copy.copy(options), streams[n], n)
|
|
|
|
if stream["Target"] == "Streaming":
|
|
|
|
options.other = "-v -y '%s'" % stream['Uri'].replace("rtmp://vod.dr.dk/cms/", "")
|
|
|
|
rtmp = "rtmp://vod.dr.dk/cms/"
|
|
|
|
yield RTMP(copy.copy(options), rtmp, stream['Bitrate'])
|
|
|
|
|
2015-09-01 00:37:06 +02:00
|
|
|
def find_stream(self, options, resource):
|
|
|
|
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
|
|
|
|
for i in links:
|
|
|
|
if i["Target"] == "Ios" or i["Target"] == "HLS":
|
|
|
|
streams = hlsparse(i["Uri"], self.http.request("get", i["Uri"]).text)
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield HLS(copy.copy(options), streams[n], n)
|
|
|
|
else:
|
|
|
|
if i["Target"] == "Streaming":
|
|
|
|
options.other = "-y '%s'" % i["Uri"].replace("rtmp://vod.dr.dk/cms/", "")
|
|
|
|
rtmp = "rtmp://vod.dr.dk/cms/"
|
|
|
|
yield RTMP(copy.copy(options), rtmp, i["Bitrate"])
|