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 -*-
|
2013-03-01 23:39:42 +01:00
|
|
|
from __future__ import absolute_import
|
2013-02-12 19:43:37 +01:00
|
|
|
import re
|
2014-01-26 01:50:54 +01:00
|
|
|
import json
|
2014-06-07 20:48:44 +02:00
|
|
|
import copy
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-26 01:51:35 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2013-09-15 00:29:26 +02:00
|
|
|
from svtplay_dl.utils.urllib import urlparse
|
2014-04-27 13:24:44 +02:00
|
|
|
from svtplay_dl.fetcher.hds import hdsparse
|
2015-10-04 14:37:16 +02:00
|
|
|
from svtplay_dl.fetcher.hls import hlsparse
|
2014-08-31 01:20:36 +02:00
|
|
|
from svtplay_dl.subtitle import subtitle
|
2015-09-06 14:19:10 +02:00
|
|
|
from svtplay_dl.error import ServiceError
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2015-09-15 20:10:32 +02:00
|
|
|
|
2014-01-26 01:51:35 +01:00
|
|
|
class Nrk(Service, OpenGraphThumbMixin):
|
2016-03-15 21:00:44 +01:00
|
|
|
supported_domains = ['nrk.no', 'tv.nrk.no', 'p3.no', 'tv.nrksuper.no']
|
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
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
if self.exclude(self.options):
|
2015-09-06 23:04:48 +02:00
|
|
|
yield ServiceError("Excluding video")
|
2014-12-22 17:41:40 +01:00
|
|
|
return
|
|
|
|
|
2014-12-08 23:07:02 +01:00
|
|
|
match = re.search("data-subtitlesurl = \"(/.*)\"", data)
|
2014-11-26 15:59:38 +01:00
|
|
|
|
2014-04-21 19:53:03 +02:00
|
|
|
if match:
|
|
|
|
parse = urlparse(self.url)
|
2014-08-31 01:20:36 +02:00
|
|
|
suburl = "%s://%s%s" % (parse.scheme, parse.netloc, match.group(1))
|
2015-12-26 11:46:14 +01:00
|
|
|
yield subtitle(copy.copy(self.options), "tt", suburl)
|
2014-09-21 19:12:17 +02:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
if self.options.force_subtitle:
|
2014-09-21 19:12:17 +02:00
|
|
|
return
|
|
|
|
|
2015-08-30 00:06:20 +02:00
|
|
|
match = re.search(r'data-media="(.*manifest.f4m)"', self.get_urldata())
|
2014-01-26 01:50:54 +01:00
|
|
|
if match:
|
|
|
|
manifest_url = match.group(1)
|
|
|
|
else:
|
2015-09-01 00:23:19 +02:00
|
|
|
match = re.search(r'data-nrk-id="([^"]+)"></div><script', self.get_urldata())
|
2014-01-26 01:50:54 +01:00
|
|
|
if match is None:
|
2015-09-01 00:23:19 +02:00
|
|
|
match = re.search(r'video-id="([^"]+)"', self.get_urldata())
|
|
|
|
if match is None:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't find video id.")
|
2015-09-01 00:23:19 +02:00
|
|
|
return
|
2014-01-26 01:50:54 +01:00
|
|
|
vid = match.group(1)
|
2015-09-01 00:23:19 +02:00
|
|
|
dataurl = "http://v8.psapi.nrk.no/mediaelement/%s" % vid
|
|
|
|
data = self.http.request("get", dataurl).text
|
2014-12-08 23:07:02 +01:00
|
|
|
data = json.loads(data)
|
2014-01-26 01:50:54 +01:00
|
|
|
manifest_url = data["mediaUrl"]
|
2015-12-26 11:46:14 +01:00
|
|
|
self.options.live = data["isLive"]
|
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:
|
2015-09-06 14:19:10 +02:00
|
|
|
yield ServiceError("Can't fetch the video because of geoblocked")
|
2015-09-01 00:23:19 +02:00
|
|
|
return
|
2015-12-26 11:46:14 +01:00
|
|
|
streams = hlsparse(self.options, data, hlsurl)
|
2014-06-07 20:48:44 +02:00
|
|
|
for n in list(streams.keys()):
|
2015-10-04 14:37:16 +02:00
|
|
|
yield streams[n]
|
2014-06-07 20:48:44 +02:00
|
|
|
|
2015-12-26 11:46:14 +01:00
|
|
|
streams = hdsparse(copy.copy(self.options), self.http.request("get", manifest_url, params={"hdcore": "3.7.0"}), manifest_url)
|
2014-10-12 23:31:02 +02:00
|
|
|
if streams:
|
|
|
|
for n in list(streams.keys()):
|
|
|
|
yield streams[n]
|