# 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 base64 import re import json import copy import binascii import hashlib from urllib.parse import urljoin, urlparse from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.backends import default_backend from svtplay_dl.service import Service, OpenGraphThumbMixin from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.fetcher.hds import hdsparse from svtplay_dl.subtitle import subtitle from svtplay_dl.error import ServiceError class Dr(Service, OpenGraphThumbMixin): supported_domains = ['dr.dk'] def get(self): data = self.get_urldata() match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).content resource = json.loads(resource_data) streams = self.find_stream(self.config, resource) for i in streams: yield i else: match = re.search(r'resource="([^"]*)"', data) if not match: yield ServiceError("Cant find resource info for this video") return if match.group(1)[:4] != "http": resource_url = "http:{0}".format(match.group(1)) else: resource_url = match.group(1) resource_data = self.http.request("get", resource_url).text resource = json.loads(resource_data) if "Links" not in resource: yield ServiceError("Cant access this video. its geoblocked.") return if "SubtitlesList" in resource and len(resource["SubtitlesList"]) > 0: suburl = resource["SubtitlesList"][0]["Uri"] yield subtitle(copy.copy(self.config), "wrst", suburl, output=self.output) if "Data" in resource: streams = self.find_stream(self.config, resource) for i in streams: yield i else: for stream in resource['Links']: uri = stream["Uri"] if uri is None: uri = self._decrypt(stream["EncryptedUri"]) if stream["Target"] == "HDS": streams = hdsparse(copy.copy(self.config), self.http.request("get", uri, params={"hdcore": "3.7.0"}), uri, output=self.output) if streams: for n in list(streams.keys()): yield streams[n] if stream["Target"] == "HLS": streams = hlsparse(self.config, self.http.request("get", uri), uri, output=self.output) for n in list(streams.keys()): yield streams[n] def find_all_episodes(self, config): episodes = [] matches = re.findall(r'