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 sys
|
|
|
|
import json
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-26 01:51:35 +01:00
|
|
|
from svtplay_dl.service import Service, OpenGraphThumbMixin
|
2014-04-21 19:53:03 +02:00
|
|
|
from svtplay_dl.utils import get_http_data
|
2013-09-15 00:29:26 +02:00
|
|
|
from svtplay_dl.utils.urllib import urlparse
|
2014-04-21 18:24:57 +02:00
|
|
|
from svtplay_dl.fetcher.hds import HDS
|
|
|
|
from svtplay_dl.fetcher.hls import HLS
|
2014-04-21 19:53:03 +02:00
|
|
|
from svtplay_dl.subtitle import subtitle_tt
|
2014-01-26 01:50:54 +01:00
|
|
|
from svtplay_dl.log import log
|
2013-02-12 19:43:37 +01:00
|
|
|
|
2014-01-26 01:51:35 +01:00
|
|
|
class Nrk(Service, OpenGraphThumbMixin):
|
2014-01-26 01:27:45 +01:00
|
|
|
supported_domains = ['nrk.no', 'tv.nrk.no']
|
2013-01-17 00:21:47 +01:00
|
|
|
|
2014-01-06 23:14:06 +01:00
|
|
|
def get(self, options):
|
2014-02-18 16:48:53 +01:00
|
|
|
data = self.get_urldata()
|
2014-04-21 19:53:03 +02:00
|
|
|
match = re.search("data-subtitlesurl = \"(/.*)\"", data)
|
|
|
|
if match:
|
|
|
|
parse = urlparse(self.url)
|
|
|
|
subtitle = "%s://%s%s" % (parse.scheme, parse.netloc, match.group(1))
|
|
|
|
yield subtitle_tt(subtitle)
|
2013-01-17 00:21:47 +01:00
|
|
|
match = re.search(r'data-media="(.*manifest.f4m)"', data)
|
2014-01-26 01:50:54 +01:00
|
|
|
if match:
|
|
|
|
manifest_url = match.group(1)
|
|
|
|
else:
|
|
|
|
match = re.search(r'data-video-id="(\d+)"', data)
|
|
|
|
if match is None:
|
|
|
|
log.error("Can't find video id.")
|
|
|
|
sys.exit(2)
|
|
|
|
vid = match.group(1)
|
|
|
|
match = re.search(r"PS_VIDEO_API_URL : '([^']*)',", data)
|
|
|
|
if match is None:
|
|
|
|
log.error("Can't find server address with media info")
|
|
|
|
sys.exit(2)
|
|
|
|
dataurl = "%smediaelement/%s" % (match.group(1), vid)
|
|
|
|
data = json.loads(get_http_data(dataurl))
|
|
|
|
manifest_url = data["mediaUrl"]
|
|
|
|
options.live = data["isLive"]
|
2013-01-17 00:21:47 +01:00
|
|
|
if options.hls:
|
|
|
|
manifest_url = manifest_url.replace("/z/", "/i/").replace("manifest.f4m", "master.m3u8")
|
2014-04-21 18:24:57 +02:00
|
|
|
yield HLS(options, manifest_url, "0")
|
2013-01-17 00:21:47 +01:00
|
|
|
else:
|
|
|
|
manifest_url = "%s?hdcore=2.8.0&g=hejsan" % manifest_url
|
2014-04-21 18:24:57 +02:00
|
|
|
yield HDS(options, manifest_url, "0")
|