1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-12 12:54:18 +01:00
svtplay-dl/lib/svtplay_dl/service/nrk.py

41 lines
1.5 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 -*-
2014-06-07 20:48:44 +02:00
import copy
2019-08-25 00:40:39 +02:00
import re
2019-08-25 00:40:39 +02:00
from svtplay_dl.error import ServiceError
from svtplay_dl.fetcher.hls import hlsparse
2019-08-25 00:40:39 +02:00
from svtplay_dl.service import OpenGraphThumbMixin
from svtplay_dl.service import Service
from svtplay_dl.subtitle import subtitle_probe
2015-09-15 20:10:32 +02:00
2014-01-26 01:51:35 +01:00
class Nrk(Service, OpenGraphThumbMixin):
2019-08-25 00:27:31 +02:00
supported_domains = ["nrk.no", "tv.nrk.no", "p3.no", "tv.nrksuper.no"]
def get(self):
# First, fint the video ID from the html document
2021-04-02 14:06:56 +02:00
match = re.search('program-id" content="([^"]+)"', self.get_urldata())
2016-10-06 22:51:54 +02:00
if match:
video_id = match.group(1)
else:
yield ServiceError("Can't find video id.")
return
2022-07-09 14:26:53 +02:00
dataurl = f"https://psapi.nrk.no/playback/manifest/program/{video_id}?eea-portability=true"
janson = self.http.request("get", dataurl).json()
2014-06-07 20:48:44 +02:00
2022-07-09 14:26:53 +02:00
if janson["playable"]:
if janson["playable"]["assets"][0]["format"] == "HLS":
yield from hlsparse(
self.config,
self.http.request("get", janson["playable"]["assets"][0]["url"]),
janson["playable"]["assets"][0]["url"],
output=self.output,
)
# Check if subtitles are available
for sub in janson["playable"]["subtitles"]:
if sub["defaultOn"]:
yield from subtitle_probe(copy.copy(self.config), sub["webVtt"], output=self.output)