1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-24 20:25:41 +01:00
svtplay-dl/lib/svtplay_dl/service/nrk.py

60 lines
2.2 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 json
import re
2019-08-25 00:40:39 +02:00
from svtplay_dl.error import ServiceError
2014-04-27 13:24:44 +02:00
from svtplay_dl.fetcher.hds import hdsparse
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
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
2019-08-25 00:27:31 +02:00
match = re.search('programId: "([^"]+)"', 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
# Get media element details
match = re.search("apiBaseUrl: '([^']+)'", self.get_urldata())
if not match:
yield ServiceError("Cant find apiurl.")
return
2019-08-25 00:33:51 +02:00
dataurl = "{}/mediaelement/{}".format(match.group(1), video_id)
data = self.http.request("get", dataurl).text
data = json.loads(data)
manifest_url = data["mediaUrl"]
2018-05-13 13:06:45 +02:00
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)
2014-06-07 20:48:44 +02:00
hlsurl = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8")
2015-09-01 00:23:19 +02:00
data = self.http.request("get", hlsurl)
if data.status_code == 403:
yield ServiceError("Can't fetch the video because of geoblocking")
2015-09-01 00:23:19 +02:00
return
streams = hlsparse(self.config, data, hlsurl, output=self.output)
if streams:
for n in list(streams.keys()):
yield streams[n]
2014-06-07 20:48:44 +02:00
2019-08-25 00:27:31 +02:00
streams = hdsparse(
copy.copy(self.config), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url, output=self.output
2019-08-25 00:27:31 +02:00
)
if streams:
for n in list(streams.keys()):
yield streams[n]