1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 13:44:14 +01:00

nrk: update to make it work again

This commit is contained in:
Johan Andersson 2022-07-09 14:26:53 +02:00
parent 270105e3af
commit 1f55acc3d4

View File

@ -1,7 +1,6 @@
# ex:ts=4:sw=4:sts=4:et # ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
import copy import copy
import json
import re import re
from svtplay_dl.error import ServiceError from svtplay_dl.error import ServiceError
@ -23,26 +22,19 @@ class Nrk(Service, OpenGraphThumbMixin):
yield ServiceError("Can't find video id.") yield ServiceError("Can't find video id.")
return return
# Get media element details dataurl = f"https://psapi.nrk.no/playback/manifest/program/{video_id}?eea-portability=true"
match = re.search('psapi-base-url="([^"]+)"', self.get_urldata()) janson = self.http.request("get", dataurl).json()
if not match:
yield ServiceError("Cant find apiurl.")
return
dataurl = f"{match.group(1)}/mediaelement/{video_id}"
data = self.http.request("get", dataurl).text
data = json.loads(data)
manifest_url = data["mediaUrl"]
self.config.set("live", data["isLive"])
if manifest_url is None:
yield ServiceError(data["messageType"])
return
# Check if subtitles are available
if data["subtitlesUrlPath"]:
yield subtitle(copy.copy(self.config), "tt", data["subtitlesUrlPath"], output=self.output)
hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8") if janson["playable"]:
data = self.http.request("get", hlsurl) if janson["playable"]["assets"][0]["format"] == "HLS":
if data.status_code == 403: yield from hlsparse(
yield ServiceError("Can't fetch the video because of geoblocking") self.config,
return self.http.request("get", janson["playable"]["assets"][0]["url"]),
yield from hlsparse(self.config, data, hlsurl, output=self.output) janson["playable"]["assets"][0]["url"],
output=self.output,
)
# Check if subtitles are available
for sub in janson["playable"]["subtitles"]:
if sub["defaultOn"]:
yield subtitle(copy.copy(self.config), "tt", sub["webVtt"], output=self.output)