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/dr.py

87 lines
3.3 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
2014-06-07 20:43:40 +02:00
import copy
2014-01-26 01:51:53 +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
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
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):
2014-12-08 23:07:02 +01:00
error, data = self.get_urldata()
if error:
2014-11-25 23:20:14 +01:00
log.error("Can't download page.")
2014-12-08 23:07:02 +01:00
return
if self.exclude(options):
return
match = re.search(r'resource:[ ]*"([^"]*)",', data)
2013-09-14 22:39:37 +02:00
if match:
resource_url = match.group(1)
2014-12-08 23:07:02 +01:00
error, resource_data = get_http_data(resource_url)
if error:
2014-11-25 23:20:14 +01:00
log.error("Can't get resource data")
return
2013-09-14 22:39:37 +02:00
resource = json.loads(resource_data)
streams = find_stream(options, resource)
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:
log.error("Cant find resource info for this video")
2014-10-06 23:21:43 +02:00
return
2014-06-02 21:43:22 +02:00
resource_url = "%s" % match.group(1)
2014-12-08 23:07:02 +01:00
error, resource_data = get_http_data(resource_url)
if error:
2014-11-25 23:20:14 +01:00
log.error("Can't get resource data")
return
2013-09-14 22:39:37 +02:00
resource = json.loads(resource_data)
2013-09-14 21:58:55 +02:00
if "Data" in resource:
streams = find_stream(options, resource)
for i in streams:
yield i
else:
for stream in resource['Links']:
if stream["Target"] == "HDS":
streams = hdsparse(copy.copy(options), stream["Uri"])
if streams:
for n in list(streams.keys()):
yield streams[n]
if stream["Target"] == "HLS":
streams = hlsparse(stream["Uri"])
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'])
def find_stream(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"])
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"])