diff --git a/lib/svtplay_dl/service/dr.py b/lib/svtplay_dl/service/dr.py index ddf3d59..7e35cf5 100644 --- a/lib/svtplay_dl/service/dr.py +++ b/lib/svtplay_dl/service/dr.py @@ -1,20 +1,10 @@ -# ex:ts=4:sw=4:sts=4:et -# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- -import base64 -import binascii import copy -import hashlib import json +import logging import re -from urllib.parse import urljoin -from urllib.parse import urlparse +import uuid -from cryptography.hazmat.backends import default_backend -from cryptography.hazmat.primitives.ciphers import algorithms -from cryptography.hazmat.primitives.ciphers import Cipher -from cryptography.hazmat.primitives.ciphers import modes from svtplay_dl.error import ServiceError -from svtplay_dl.fetcher.hds import hdsparse from svtplay_dl.fetcher.hls import hlsparse from svtplay_dl.service import OpenGraphThumbMixin from svtplay_dl.service import Service @@ -27,113 +17,61 @@ class Dr(Service, OpenGraphThumbMixin): 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) - yield from streams - 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:{}".format(match.group(1)) - else: - resource_url = match.group(1) - resource_data = self.http.request("get", resource_url).text - resource = json.loads(resource_data) + match = re.search("__data = ([^<]+)", data) + if not match: + yield ServiceError("Cant find info for this video") + return + janson = json.loads(match.group(1)) + page = janson["cache"]["page"][list(janson["cache"]["page"].keys())[0]] + offers = page["entries"][0]["item"]["offers"] + resolution = None + vid = None + for i in offers: + if i["deliveryType"] == "Stream": + vid = i["scopes"][0] + resolution = i["resolution"] - 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) - yield from streams - else: - for stream in resource["Links"]: - uri = stream["Uri"] - if uri is None: - uri = self._decrypt(stream["EncryptedUri"]) + deviceid = uuid.uuid1() + res = self.http.request( + "post", + "https://isl.dr-massive.com/api/authorization/anonymous-sso?device=web_browser&ff=idp%2Cldp&lang=da", + json={"deviceId": str(deviceid), "scopes": ["Catalog"], "optout": True}, + ) + token = res.json()[0]["value"] - 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) + url = "https://isl.dr-massive.com/api/account/items/{}/videos?delivery=stream&device=web_browser&ff=idp%2Cldp&lang=da&resolution={}&sub=Anonymous".format( + vid, resolution + ) + res = self.http.request("get", url, headers={"authorization": "Bearer {}".format(token)}) + for video in res.json(): + if video["accessService"] == "StandardVideo": + if video["format"] == "video/hls": + res = self.http.request("get", video["url"]) + if res.status_code > 400: + yield ServiceError("Can't play this because the video is geoblocked or not available.") + else: + streams = hlsparse(self.config, res, video["url"], output=self.output) for n in list(streams.keys()): yield streams[n] + yield subtitle(copy.copy(self.config), "wrst", video["subtitles"][0]["link"], output=self.output) def find_all_episodes(self, config): episodes = [] - matches = re.findall(r'