2019-08-25 00:40:39 +02:00
|
|
|
import copy
|
|
|
|
import json
|
2020-07-30 22:39:27 +02:00
|
|
|
import logging
|
2019-08-25 00:40:39 +02:00
|
|
|
import re
|
2020-07-30 22:39:27 +02:00
|
|
|
import uuid
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2019-08-25 00:40:39 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
|
|
|
from svtplay_dl.service import OpenGraphThumbMixin
|
|
|
|
from svtplay_dl.service import Service
|
2015-03-01 21:46:22 +01:00
|
|
|
from svtplay_dl.subtitle import subtitle
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2018-01-30 20:11:37 +01:00
|
|
|
|
2014-01-26 01:51:53 +01:00
|
|
|
class Dr(Service, OpenGraphThumbMixin):
|
2019-08-25 00:27:31 +02:00
|
|
|
supported_domains = ["dr.dk"]
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
def get(self):
|
2015-08-30 00:06:20 +02:00
|
|
|
data = self.get_urldata()
|
2014-12-22 17:41:40 +01:00
|
|
|
|
2020-07-30 22:39:27 +02:00
|
|
|
match = re.search("__data = ([^<]+)</script>", 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"]
|
|
|
|
|
|
|
|
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"]
|
|
|
|
|
|
|
|
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)
|
2014-08-11 19:46:56 +02:00
|
|
|
for n in list(streams.keys()):
|
2015-10-04 14:37:16 +02:00
|
|
|
yield streams[n]
|
2020-07-30 22:39:27 +02:00
|
|
|
yield subtitle(copy.copy(self.config), "wrst", video["subtitles"][0]["link"], output=self.output)
|
2014-08-11 19:46:56 +02:00
|
|
|
|
2018-05-22 00:02:20 +02:00
|
|
|
def find_all_episodes(self, config):
|
2016-06-29 23:58:37 +02:00
|
|
|
episodes = []
|
2020-07-30 22:39:27 +02:00
|
|
|
data = self.get_urldata()
|
|
|
|
match = re.search("__data = ([^<]+)</script>", data)
|
|
|
|
if not match:
|
|
|
|
logging.error("Can't find video info.")
|
|
|
|
return episodes
|
|
|
|
janson = json.loads(match.group(1))
|
|
|
|
page = janson["cache"]["page"][list(janson["cache"]["page"].keys())[0]]
|
|
|
|
item = page["entries"][0]["item"]
|
|
|
|
if "season" in item:
|
|
|
|
entries = item["season"]["episodes"]["items"]
|
|
|
|
for i in entries:
|
|
|
|
episodes.append("https://www.dr.dk/drtv{}".format(i["watchPath"]))
|
|
|
|
|
|
|
|
if config.get("all_last") != -1:
|
|
|
|
episodes = episodes[: config.get("all_last")]
|
2016-06-29 23:58:37 +02:00
|
|
|
else:
|
2020-07-30 22:39:27 +02:00
|
|
|
episodes.reverse()
|
2016-06-29 23:58:37 +02:00
|
|
|
return episodes
|