|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
# coding: utf-8
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
import itertools
|
|
|
|
|
import random
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
@ -12,17 +14,57 @@ from ..utils import (
|
|
|
|
|
determine_ext,
|
|
|
|
|
ExtractorError,
|
|
|
|
|
int_or_none,
|
|
|
|
|
js_to_json,
|
|
|
|
|
NO_DEFAULT,
|
|
|
|
|
parse_age_limit,
|
|
|
|
|
parse_duration,
|
|
|
|
|
try_get,
|
|
|
|
|
urljoin,
|
|
|
|
|
url_or_none,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NRKBaseIE(InfoExtractor):
|
|
|
|
|
_GEO_COUNTRIES = ['NO']
|
|
|
|
|
_CDN_REPL_REGEX = r'''(?x)://
|
|
|
|
|
(?:
|
|
|
|
|
nrkod\d{1,2}-httpcache0-47115-cacheod0\.dna\.ip-only\.net/47115-cacheod0|
|
|
|
|
|
nrk-od-no\.telenorcdn\.net|
|
|
|
|
|
minicdn-od\.nrk\.no/od/nrkhd-osl-rr\.netwerk\.no/no
|
|
|
|
|
)/'''
|
|
|
|
|
|
|
|
|
|
def _extract_nrk_formats(self, asset_url, video_id):
|
|
|
|
|
if re.match(r'https?://[^/]+\.akamaihd\.net/i/', asset_url):
|
|
|
|
|
return self._extract_akamai_formats(
|
|
|
|
|
re.sub(r'(?:b=\d+-\d+|__a__=off)&?', '', asset_url), video_id)
|
|
|
|
|
asset_url = re.sub(r'(?:bw_(?:low|high)=\d+|no_audio_only)&?', '', asset_url)
|
|
|
|
|
formats = self._extract_m3u8_formats(
|
|
|
|
|
asset_url, video_id, 'mp4', 'm3u8_native', fatal=False)
|
|
|
|
|
if not formats and re.search(self._CDN_REPL_REGEX, asset_url):
|
|
|
|
|
formats = self._extract_m3u8_formats(
|
|
|
|
|
re.sub(self._CDN_REPL_REGEX, '://nrk-od-%02d.akamaized.net/no/' % random.randint(0, 99), asset_url),
|
|
|
|
|
video_id, 'mp4', 'm3u8_native', fatal=False)
|
|
|
|
|
return formats
|
|
|
|
|
|
|
|
|
|
def _raise_error(self, data):
|
|
|
|
|
MESSAGES = {
|
|
|
|
|
'ProgramRightsAreNotReady': 'Du kan dessverre ikke se eller høre programmet',
|
|
|
|
|
'ProgramRightsHasExpired': 'Programmet har gått ut',
|
|
|
|
|
'NoProgramRights': 'Ikke tilgjengelig',
|
|
|
|
|
'ProgramIsGeoBlocked': 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
|
|
|
|
|
}
|
|
|
|
|
message_type = data.get('messageType', '')
|
|
|
|
|
# Can be ProgramIsGeoBlocked or ChannelIsGeoBlocked*
|
|
|
|
|
if 'IsGeoBlocked' in message_type or try_get(data, lambda x: x['usageRights']['isGeoBlocked']) is True:
|
|
|
|
|
self.raise_geo_restricted(
|
|
|
|
|
msg=MESSAGES.get('ProgramIsGeoBlocked'),
|
|
|
|
|
countries=self._GEO_COUNTRIES)
|
|
|
|
|
message = data.get('endUserMessage') or MESSAGES.get(message_type, message_type)
|
|
|
|
|
raise ExtractorError('%s said: %s' % (self.IE_NAME, message), expected=True)
|
|
|
|
|
|
|
|
|
|
def _call_api(self, path, video_id, item=None, note=None, fatal=True, query=None):
|
|
|
|
|
return self._download_json(
|
|
|
|
|
urljoin('http://psapi.nrk.no/', path),
|
|
|
|
|
video_id, note or 'Downloading %s JSON' % item,
|
|
|
|
|
fatal=fatal, query=query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NRKIE(NRKBaseIE):
|
|
|
|
@ -41,7 +83,7 @@ class NRKIE(NRKBaseIE):
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
# video
|
|
|
|
|
'url': 'http://www.nrk.no/video/PS*150533',
|
|
|
|
|
'md5': '706f34cdf1322577589e369e522b50ef',
|
|
|
|
|
'md5': 'f46be075326e23ad0e524edfcb06aeb6',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '150533',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
@ -55,7 +97,7 @@ class NRKIE(NRKBaseIE):
|
|
|
|
|
# MD5 is unstable
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '154915',
|
|
|
|
|
'ext': 'flv',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Slik høres internett ut når du er blind',
|
|
|
|
|
'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
|
|
|
|
|
'duration': 20,
|
|
|
|
@ -78,9 +120,15 @@ class NRKIE(NRKBaseIE):
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
def _extract_from_playback(self, video_id):
|
|
|
|
|
manifest = self._download_json(
|
|
|
|
|
'http://psapi.nrk.no/playback/manifest/%s' % video_id,
|
|
|
|
|
video_id, 'Downloading manifest JSON')
|
|
|
|
|
path_templ = 'playback/%s/' + video_id
|
|
|
|
|
|
|
|
|
|
def call_playback_api(item, query=None):
|
|
|
|
|
return self._call_api(path_templ % item, video_id, item, query=query)
|
|
|
|
|
# known values for preferredCdn: akamai, iponly, minicdn and telenor
|
|
|
|
|
manifest = call_playback_api('manifest', {'preferredCdn': 'akamai'})
|
|
|
|
|
|
|
|
|
|
if manifest.get('playability') == 'nonPlayable':
|
|
|
|
|
self._raise_error(manifest['nonPlayable'])
|
|
|
|
|
|
|
|
|
|
playable = manifest['playable']
|
|
|
|
|
|
|
|
|
@ -94,14 +142,10 @@ class NRKIE(NRKBaseIE):
|
|
|
|
|
if not format_url:
|
|
|
|
|
continue
|
|
|
|
|
if asset.get('format') == 'HLS' or determine_ext(format_url) == 'm3u8':
|
|
|
|
|
formats.extend(self._extract_m3u8_formats(
|
|
|
|
|
format_url, video_id, 'mp4', entry_protocol='m3u8_native',
|
|
|
|
|
m3u8_id='hls', fatal=False))
|
|
|
|
|
formats.extend(self._extract_nrk_formats(format_url, video_id))
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
|
|
data = self._download_json(
|
|
|
|
|
'http://psapi.nrk.no/playback/metadata/%s' % video_id,
|
|
|
|
|
video_id, 'Downloading metadata JSON')
|
|
|
|
|
data = call_playback_api('metadata')
|
|
|
|
|
|
|
|
|
|
preplay = data['preplay']
|
|
|
|
|
titles = preplay['titles']
|
|
|
|
@ -143,29 +187,22 @@ class NRKIE(NRKBaseIE):
|
|
|
|
|
class NRKTVIE(NRKBaseIE):
|
|
|
|
|
IE_DESC = 'NRK TV and NRK Radio'
|
|
|
|
|
_EPISODE_RE = r'(?P<id>[a-zA-Z]{4}\d{8})'
|
|
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
|
https?://
|
|
|
|
|
(?:tv|radio)\.nrk(?:super)?\.no/
|
|
|
|
|
(?:serie(?:/[^/]+){1,2}|program)/
|
|
|
|
|
(?![Ee]pisodes)%s
|
|
|
|
|
(?:/\d{2}-\d{2}-\d{4})?
|
|
|
|
|
(?:\#del=(?P<part_id>\d+))?
|
|
|
|
|
''' % _EPISODE_RE
|
|
|
|
|
_VALID_URL = r'https?://(?:tv|radio)\.nrk(?:super)?\.no/(?:[^/]+/)*%s' % _EPISODE_RE
|
|
|
|
|
_API_HOSTS = ('psapi-ne.nrk.no', 'psapi-we.nrk.no')
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://tv.nrk.no/program/MDDP12000117',
|
|
|
|
|
'md5': '8270824df46ec629b66aeaa5796b36fb',
|
|
|
|
|
'md5': 'c4a5960f1b00b40d47db65c1064e0ab1',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'MDDP12000117AA',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Alarm Trolltunga',
|
|
|
|
|
'description': 'md5:46923a6e6510eefcce23d5ef2a58f2ce',
|
|
|
|
|
'duration': 2223,
|
|
|
|
|
'duration': 2223.44,
|
|
|
|
|
'age_limit': 6,
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
|
|
|
|
|
'md5': '9a167e54d04671eb6317a37b7bc8a280',
|
|
|
|
|
'md5': '8d40dab61cea8ab0114e090b029a0565',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'MUHH48000314AA',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
@ -175,7 +212,6 @@ class NRKTVIE(NRKBaseIE):
|
|
|
|
|
'series': '20 spørsmål',
|
|
|
|
|
'episode': '23.05.2014',
|
|
|
|
|
},
|
|
|
|
|
'skip': 'NoProgramRights',
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://tv.nrk.no/program/mdfp15000514',
|
|
|
|
|
'info_dict': {
|
|
|
|
@ -183,7 +219,7 @@ class NRKTVIE(NRKBaseIE):
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Grunnlovsjubiléet - Stor ståhei for ingenting 24.05.2014',
|
|
|
|
|
'description': 'md5:89290c5ccde1b3a24bb8050ab67fe1db',
|
|
|
|
|
'duration': 4605,
|
|
|
|
|
'duration': 4605.08,
|
|
|
|
|
'series': 'Kunnskapskanalen',
|
|
|
|
|
'episode': '24.05.2014',
|
|
|
|
|
},
|
|
|
|
@ -194,51 +230,25 @@ class NRKTVIE(NRKBaseIE):
|
|
|
|
|
# single playlist video
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'MSPO40010515-part2',
|
|
|
|
|
'ext': 'flv',
|
|
|
|
|
'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
|
|
|
|
|
'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
|
|
|
|
|
'id': 'MSPO40010515AH',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015',
|
|
|
|
|
'description': 'md5:c03aba1e917561eface5214020551b7a',
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
'expected_warnings': ['Video is geo restricted'],
|
|
|
|
|
'expected_warnings': ['Failed to download m3u8 information'],
|
|
|
|
|
'skip': 'particular part is not supported currently',
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
|
|
|
|
|
'playlist': [{
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'MSPO40010515AH',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015 (Part 1)',
|
|
|
|
|
'description': 'md5:1f97a41f05a9486ee00c56f35f82993d',
|
|
|
|
|
'duration': 772,
|
|
|
|
|
'series': 'Tour de Ski',
|
|
|
|
|
'episode': '06.01.2015',
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
}, {
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'MSPO40010515BH',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015 (Part 2)',
|
|
|
|
|
'description': 'md5:1f97a41f05a9486ee00c56f35f82993d',
|
|
|
|
|
'duration': 6175,
|
|
|
|
|
'series': 'Tour de Ski',
|
|
|
|
|
'episode': '06.01.2015',
|
|
|
|
|
},
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
}],
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'MSPO40010515',
|
|
|
|
|
'id': 'MSPO40010515AH',
|
|
|
|
|
'ext': 'mp4',
|
|
|
|
|
'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015',
|
|
|
|
|
'description': 'md5:1f97a41f05a9486ee00c56f35f82993d',
|
|
|
|
|
'description': 'md5:c03aba1e917561eface5214020551b7a',
|
|
|
|
|
},
|
|
|
|
|
'expected_warnings': ['Video is geo restricted'],
|
|
|
|
|
'expected_warnings': ['Failed to download m3u8 information'],
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/anno/KMTE50001317/sesong-3/episode-13',
|
|
|
|
|
'info_dict': {
|
|
|
|
@ -269,12 +279,16 @@ class NRKTVIE(NRKBaseIE):
|
|
|
|
|
'params': {
|
|
|
|
|
'skip_download': True,
|
|
|
|
|
},
|
|
|
|
|
'skip': 'ProgramRightsHasExpired',
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://radio.nrk.no/serie/dagsnytt/NPUB21019315/12-07-2015#',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/lindmo/2018/MUHU11006318/avspiller',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://radio.nrk.no/serie/dagsnytt/sesong/201507/NPUB21019315',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
_api_host = None
|
|
|
|
@ -295,6 +309,7 @@ class NRKTVIE(NRKBaseIE):
|
|
|
|
|
title = data.get('fullTitle') or data.get('mainTitle') or data['title']
|
|
|
|
|
video_id = data.get('id') or video_id
|
|
|
|
|
|
|
|
|
|
urls = []
|
|
|
|
|
entries = []
|
|
|
|
|
|
|
|
|
|
conviva = data.get('convivaStatistics') or {}
|
|
|
|
@ -311,19 +326,14 @@ class NRKTVIE(NRKBaseIE):
|
|
|
|
|
else ('%s-%d' % (video_id, idx), '%s (Part %d)' % (title, idx)))
|
|
|
|
|
for num, asset in enumerate(media_assets, 1):
|
|
|
|
|
asset_url = asset.get('url')
|
|
|
|
|
if not asset_url:
|
|
|
|
|
if not asset_url or asset_url in urls:
|
|
|
|
|
continue
|
|
|
|
|
formats = self._extract_akamai_formats(asset_url, video_id)
|
|
|
|
|
urls.append(asset_url)
|
|
|
|
|
formats = self._extract_nrk_formats(asset_url, video_id)
|
|
|
|
|
if not formats:
|
|
|
|
|
continue
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
|
|
# Some f4m streams may not work with hdcore in fragments' URLs
|
|
|
|
|
for f in formats:
|
|
|
|
|
extra_param = f.get('extra_param_to_segment_url')
|
|
|
|
|
if extra_param and 'hdcore' in extra_param:
|
|
|
|
|
del f['extra_param_to_segment_url']
|
|
|
|
|
|
|
|
|
|
entry_id, entry_title = video_id_and_title(num)
|
|
|
|
|
duration = parse_duration(asset.get('duration'))
|
|
|
|
|
subtitles = {}
|
|
|
|
@ -339,38 +349,26 @@ class NRKTVIE(NRKBaseIE):
|
|
|
|
|
'duration': duration,
|
|
|
|
|
'subtitles': subtitles,
|
|
|
|
|
'formats': formats,
|
|
|
|
|
'is_live': live,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if not entries:
|
|
|
|
|
media_url = data.get('mediaUrl')
|
|
|
|
|
if media_url:
|
|
|
|
|
formats = self._extract_akamai_formats(media_url, video_id)
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
duration = parse_duration(data.get('duration'))
|
|
|
|
|
entries = [{
|
|
|
|
|
'id': video_id,
|
|
|
|
|
'title': make_title(title),
|
|
|
|
|
'duration': duration,
|
|
|
|
|
'formats': formats,
|
|
|
|
|
}]
|
|
|
|
|
if media_url and media_url not in urls:
|
|
|
|
|
formats = self._extract_nrk_formats(media_url, video_id)
|
|
|
|
|
if formats:
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
duration = parse_duration(data.get('duration'))
|
|
|
|
|
entries = [{
|
|
|
|
|
'id': video_id,
|
|
|
|
|
'title': make_title(title),
|
|
|
|
|
'duration': duration,
|
|
|
|
|
'formats': formats,
|
|
|
|
|
'is_live': live,
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
if not entries:
|
|
|
|
|
MESSAGES = {
|
|
|
|
|
'ProgramRightsAreNotReady': 'Du kan dessverre ikke se eller høre programmet',
|
|
|
|
|
'ProgramRightsHasExpired': 'Programmet har gått ut',
|
|
|
|
|
'NoProgramRights': 'Ikke tilgjengelig',
|
|
|
|
|
'ProgramIsGeoBlocked': 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
|
|
|
|
|
}
|
|
|
|
|
message_type = data.get('messageType', '')
|
|
|
|
|
# Can be ProgramIsGeoBlocked or ChannelIsGeoBlocked*
|
|
|
|
|
if 'IsGeoBlocked' in message_type:
|
|
|
|
|
self.raise_geo_restricted(
|
|
|
|
|
msg=MESSAGES.get('ProgramIsGeoBlocked'),
|
|
|
|
|
countries=self._GEO_COUNTRIES)
|
|
|
|
|
raise ExtractorError(
|
|
|
|
|
'%s said: %s' % (self.IE_NAME, MESSAGES.get(
|
|
|
|
|
message_type, message_type)),
|
|
|
|
|
expected=True)
|
|
|
|
|
self._raise_error(data)
|
|
|
|
|
|
|
|
|
|
series = conviva.get('seriesName') or data.get('seriesTitle')
|
|
|
|
|
episode = conviva.get('episodeName') or data.get('episodeNumberOrDate')
|
|
|
|
@ -512,57 +510,98 @@ class NRKTVEpisodeIE(InfoExtractor):
|
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NRKTVSerieBaseIE(InfoExtractor):
|
|
|
|
|
def _extract_series(self, webpage, display_id, fatal=True):
|
|
|
|
|
config = self._parse_json(
|
|
|
|
|
self._search_regex(
|
|
|
|
|
(r'INITIAL_DATA(?:_V\d)?_*\s*=\s*({.+?})\s*;',
|
|
|
|
|
r'({.+?})\s*,\s*"[^"]+"\s*\)\s*</script>'),
|
|
|
|
|
webpage, 'config', default='{}' if not fatal else NO_DEFAULT),
|
|
|
|
|
display_id, fatal=False, transform_source=js_to_json)
|
|
|
|
|
if not config:
|
|
|
|
|
return
|
|
|
|
|
return try_get(
|
|
|
|
|
config,
|
|
|
|
|
(lambda x: x['initialState']['series'], lambda x: x['series']),
|
|
|
|
|
dict)
|
|
|
|
|
|
|
|
|
|
def _extract_seasons(self, seasons):
|
|
|
|
|
if not isinstance(seasons, list):
|
|
|
|
|
return []
|
|
|
|
|
entries = []
|
|
|
|
|
for season in seasons:
|
|
|
|
|
entries.extend(self._extract_episodes(season))
|
|
|
|
|
return entries
|
|
|
|
|
|
|
|
|
|
def _extract_episodes(self, season):
|
|
|
|
|
if not isinstance(season, dict):
|
|
|
|
|
return []
|
|
|
|
|
return self._extract_entries(season.get('episodes'))
|
|
|
|
|
|
|
|
|
|
class NRKTVSerieBaseIE(NRKBaseIE):
|
|
|
|
|
def _extract_entries(self, entry_list):
|
|
|
|
|
if not isinstance(entry_list, list):
|
|
|
|
|
return []
|
|
|
|
|
entries = []
|
|
|
|
|
for episode in entry_list:
|
|
|
|
|
nrk_id = episode.get('prfId')
|
|
|
|
|
nrk_id = episode.get('prfId') or episode.get('episodeId')
|
|
|
|
|
if not nrk_id or not isinstance(nrk_id, compat_str):
|
|
|
|
|
continue
|
|
|
|
|
if not re.match(NRKTVIE._EPISODE_RE, nrk_id):
|
|
|
|
|
continue
|
|
|
|
|
entries.append(self.url_result(
|
|
|
|
|
'nrk:%s' % nrk_id, ie=NRKIE.ie_key(), video_id=nrk_id))
|
|
|
|
|
return entries
|
|
|
|
|
|
|
|
|
|
_ASSETS_KEYS = ('episodes', 'instalments',)
|
|
|
|
|
|
|
|
|
|
def _extract_assets_key(self, embedded):
|
|
|
|
|
for asset_key in self._ASSETS_KEYS:
|
|
|
|
|
if embedded.get(asset_key):
|
|
|
|
|
return asset_key
|
|
|
|
|
|
|
|
|
|
def _entries(self, data, display_id):
|
|
|
|
|
for page_num in itertools.count(1):
|
|
|
|
|
embedded = data.get('_embedded') or data
|
|
|
|
|
if not isinstance(embedded, dict):
|
|
|
|
|
break
|
|
|
|
|
assets_key = self._extract_assets_key(embedded)
|
|
|
|
|
if not assets_key:
|
|
|
|
|
break
|
|
|
|
|
# Extract entries
|
|
|
|
|
entries = try_get(
|
|
|
|
|
embedded,
|
|
|
|
|
(lambda x: x[assets_key]['_embedded'][assets_key],
|
|
|
|
|
lambda x: x[assets_key]),
|
|
|
|
|
list)
|
|
|
|
|
for e in self._extract_entries(entries):
|
|
|
|
|
yield e
|
|
|
|
|
# Find next URL
|
|
|
|
|
next_url_path = try_get(
|
|
|
|
|
data,
|
|
|
|
|
(lambda x: x['_links']['next']['href'],
|
|
|
|
|
lambda x: x['_embedded'][assets_key]['_links']['next']['href']),
|
|
|
|
|
compat_str)
|
|
|
|
|
if not next_url_path:
|
|
|
|
|
break
|
|
|
|
|
data = self._call_api(
|
|
|
|
|
next_url_path, display_id,
|
|
|
|
|
note='Downloading %s JSON page %d' % (assets_key, page_num),
|
|
|
|
|
fatal=False)
|
|
|
|
|
if not data:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NRKTVSeasonIE(NRKTVSerieBaseIE):
|
|
|
|
|
_VALID_URL = r'https?://tv\.nrk\.no/serie/[^/]+/sesong/(?P<id>\d+)'
|
|
|
|
|
_TEST = {
|
|
|
|
|
_VALID_URL = r'https?://(?P<domain>tv|radio)\.nrk\.no/serie/(?P<serie>[^/]+)/(?:sesong/)?(?P<id>\d+)'
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/backstage/sesong/1',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': '1',
|
|
|
|
|
'id': 'backstage/1',
|
|
|
|
|
'title': 'Sesong 1',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 30,
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
# no /sesong/ in path
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/lindmo/2016',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'lindmo/2016',
|
|
|
|
|
'title': '2016',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 29,
|
|
|
|
|
}, {
|
|
|
|
|
# weird nested _embedded in catalog JSON response
|
|
|
|
|
'url': 'https://radio.nrk.no/serie/dickie-dick-dickens/sesong/1',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'dickie-dick-dickens/1',
|
|
|
|
|
'title': 'Sesong 1',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 11,
|
|
|
|
|
}, {
|
|
|
|
|
# 841 entries, multi page
|
|
|
|
|
'url': 'https://radio.nrk.no/serie/dagsnytt/sesong/201509',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'dagsnytt/201509',
|
|
|
|
|
'title': 'September 2015',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 841,
|
|
|
|
|
}, {
|
|
|
|
|
# 180 entries, single page
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/spangas/sesong/1',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def suitable(cls, url):
|
|
|
|
@ -570,25 +609,35 @@ class NRKTVSeasonIE(NRKTVSerieBaseIE):
|
|
|
|
|
else super(NRKTVSeasonIE, cls).suitable(url))
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
display_id = self._match_id(url)
|
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, display_id)
|
|
|
|
|
domain, serie, season_id = re.match(self._VALID_URL, url).groups()
|
|
|
|
|
display_id = '%s/%s' % (serie, season_id)
|
|
|
|
|
|
|
|
|
|
series = self._extract_series(webpage, display_id)
|
|
|
|
|
data = self._call_api(
|
|
|
|
|
'%s/catalog/series/%s/seasons/%s' % (domain, serie, season_id),
|
|
|
|
|
display_id, 'season', query={'pageSize': 50})
|
|
|
|
|
|
|
|
|
|
season = next(
|
|
|
|
|
s for s in series['seasons']
|
|
|
|
|
if int(display_id) == s.get('seasonNumber'))
|
|
|
|
|
|
|
|
|
|
title = try_get(season, lambda x: x['titles']['title'], compat_str)
|
|
|
|
|
title = try_get(data, lambda x: x['titles']['title'], compat_str) or display_id
|
|
|
|
|
return self.playlist_result(
|
|
|
|
|
self._extract_episodes(season), display_id, title)
|
|
|
|
|
self._entries(data, display_id),
|
|
|
|
|
display_id, title)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NRKTVSeriesIE(NRKTVSerieBaseIE):
|
|
|
|
|
_VALID_URL = r'https?://(?:tv|radio)\.nrk(?:super)?\.no/serie/(?P<id>[^/]+)'
|
|
|
|
|
_ITEM_RE = r'(?:data-season=["\']|id=["\']season-)(?P<id>\d+)'
|
|
|
|
|
_VALID_URL = r'https?://(?P<domain>(?:tv|radio)\.nrk|(?:tv\.)?nrksuper)\.no/serie/(?P<id>[^/]+)'
|
|
|
|
|
_TESTS = [{
|
|
|
|
|
# new layout, instalments
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/groenn-glede',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'groenn-glede',
|
|
|
|
|
'title': 'Grønn glede',
|
|
|
|
|
'description': 'md5:7576e92ae7f65da6993cf90ee29e4608',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 90,
|
|
|
|
|
}, {
|
|
|
|
|
# new layout, instalments, more entries
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/lindmo',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/blank',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'blank',
|
|
|
|
@ -602,25 +651,16 @@ class NRKTVSeriesIE(NRKTVSerieBaseIE):
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'backstage',
|
|
|
|
|
'title': 'Backstage',
|
|
|
|
|
'description': 'md5:c3ec3a35736fca0f9e1207b5511143d3',
|
|
|
|
|
'description': 'md5:63692ceb96813d9a207e9910483d948b',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 60,
|
|
|
|
|
}, {
|
|
|
|
|
# new layout, instalments
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/groenn-glede',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'groenn-glede',
|
|
|
|
|
'title': 'Grønn glede',
|
|
|
|
|
'description': 'md5:7576e92ae7f65da6993cf90ee29e4608',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 10,
|
|
|
|
|
}, {
|
|
|
|
|
# old layout
|
|
|
|
|
'url': 'https://tv.nrksuper.no/serie/labyrint',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'labyrint',
|
|
|
|
|
'title': 'Labyrint',
|
|
|
|
|
'description': 'md5:318b597330fdac5959247c9b69fdb1ec',
|
|
|
|
|
'description': 'I Daidalos sin undersjøiske Labyrint venter spennende oppgaver, skumle robotskapninger og slim.',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 3,
|
|
|
|
|
}, {
|
|
|
|
@ -632,6 +672,17 @@ class NRKTVSeriesIE(NRKTVSerieBaseIE):
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://tv.nrk.no/serie/postmann-pat',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://radio.nrk.no/serie/dickie-dick-dickens',
|
|
|
|
|
'info_dict': {
|
|
|
|
|
'id': 'dickie-dick-dickens',
|
|
|
|
|
'title': 'Dickie Dick Dickens',
|
|
|
|
|
'description': 'md5:19e67411ffe57f7dce08a943d7a0b91f',
|
|
|
|
|
},
|
|
|
|
|
'playlist_mincount': 8,
|
|
|
|
|
}, {
|
|
|
|
|
'url': 'https://nrksuper.no/serie/labyrint',
|
|
|
|
|
'only_matching': True,
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@ -642,43 +693,42 @@ class NRKTVSeriesIE(NRKTVSerieBaseIE):
|
|
|
|
|
else super(NRKTVSeriesIE, cls).suitable(url))
|
|
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
series_id = self._match_id(url)
|
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, series_id)
|
|
|
|
|
|
|
|
|
|
# New layout (e.g. https://tv.nrk.no/serie/backstage)
|
|
|
|
|
series = self._extract_series(webpage, series_id, fatal=False)
|
|
|
|
|
if series:
|
|
|
|
|
title = try_get(series, lambda x: x['titles']['title'], compat_str)
|
|
|
|
|
description = try_get(
|
|
|
|
|
series, lambda x: x['titles']['subtitle'], compat_str)
|
|
|
|
|
entries = []
|
|
|
|
|
entries.extend(self._extract_seasons(series.get('seasons')))
|
|
|
|
|
entries.extend(self._extract_entries(series.get('instalments')))
|
|
|
|
|
entries.extend(self._extract_episodes(series.get('extraMaterial')))
|
|
|
|
|
return self.playlist_result(entries, series_id, title, description)
|
|
|
|
|
|
|
|
|
|
# Old layout (e.g. https://tv.nrksuper.no/serie/labyrint)
|
|
|
|
|
entries = [
|
|
|
|
|
self.url_result(
|
|
|
|
|
'https://tv.nrk.no/program/Episodes/{series}/{season}'.format(
|
|
|
|
|
series=series_id, season=season_id))
|
|
|
|
|
for season_id in re.findall(self._ITEM_RE, webpage)
|
|
|
|
|
]
|
|
|
|
|
site, series_id = re.match(self._VALID_URL, url).groups()
|
|
|
|
|
is_radio = site == 'radio.nrk'
|
|
|
|
|
domain = 'radio' if is_radio else 'tv'
|
|
|
|
|
|
|
|
|
|
size_prefix = 'p' if is_radio else 'embeddedInstalmentsP'
|
|
|
|
|
series = self._call_api(
|
|
|
|
|
'%s/catalog/series/%s' % (domain, series_id),
|
|
|
|
|
series_id, 'serie', query={size_prefix + 'ageSize': 50})
|
|
|
|
|
titles = try_get(series, [
|
|
|
|
|
lambda x: x['titles'],
|
|
|
|
|
lambda x: x[x['type']]['titles'],
|
|
|
|
|
lambda x: x[x['seriesType']]['titles'],
|
|
|
|
|
]) or {}
|
|
|
|
|
|
|
|
|
|
title = self._html_search_meta(
|
|
|
|
|
'seriestitle', webpage,
|
|
|
|
|
'title', default=None) or self._og_search_title(
|
|
|
|
|
webpage, fatal=False)
|
|
|
|
|
if title:
|
|
|
|
|
title = self._search_regex(
|
|
|
|
|
r'NRK (?:Super )?TV\s*[-–]\s*(.+)', title, 'title', default=title)
|
|
|
|
|
|
|
|
|
|
description = self._html_search_meta(
|
|
|
|
|
'series_description', webpage,
|
|
|
|
|
'description', default=None) or self._og_search_description(webpage)
|
|
|
|
|
entries = []
|
|
|
|
|
entries.extend(self._entries(series, series_id))
|
|
|
|
|
embedded = series.get('_embedded') or {}
|
|
|
|
|
linked_seasons = try_get(series, lambda x: x['_links']['seasons']) or []
|
|
|
|
|
embedded_seasons = embedded.get('seasons') or []
|
|
|
|
|
if len(linked_seasons) > len(embedded_seasons):
|
|
|
|
|
for season in linked_seasons:
|
|
|
|
|
season_name = season.get('name')
|
|
|
|
|
if season_name and isinstance(season_name, compat_str):
|
|
|
|
|
entries.append(self.url_result(
|
|
|
|
|
'https://%s.nrk.no/serie/%s/sesong/%s'
|
|
|
|
|
% (domain, series_id, season_name),
|
|
|
|
|
ie=NRKTVSeasonIE.ie_key(),
|
|
|
|
|
video_title=season.get('title')))
|
|
|
|
|
else:
|
|
|
|
|
for season in embedded_seasons:
|
|
|
|
|
entries.extend(self._entries(season, series_id))
|
|
|
|
|
entries.extend(self._entries(
|
|
|
|
|
embedded.get('extraMaterial') or {}, series_id))
|
|
|
|
|
|
|
|
|
|
return self.playlist_result(entries, series_id, title, description)
|
|
|
|
|
return self.playlist_result(
|
|
|
|
|
entries, series_id, titles.get('title'), titles.get('subtitle'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NRKTVDirekteIE(NRKTVIE):
|
|
|
|
@ -782,14 +832,8 @@ class NRKSkoleIE(InfoExtractor):
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
|
video_id = self._match_id(url)
|
|
|
|
|
|
|
|
|
|
webpage = self._download_webpage(
|
|
|
|
|
'https://mimir.nrk.no/plugin/1.0/static?mediaId=%s' % video_id,
|
|
|
|
|
video_id)
|
|
|
|
|
|
|
|
|
|
nrk_id = self._parse_json(
|
|
|
|
|
self._search_regex(
|
|
|
|
|
r'<script[^>]+type=["\']application/json["\'][^>]*>({.+?})</script>',
|
|
|
|
|
webpage, 'application json'),
|
|
|
|
|
video_id)['activeMedia']['psId']
|
|
|
|
|
nrk_id = self._download_json(
|
|
|
|
|
'https://nrkno-skole-prod.kube.nrk.no/skole/api/media/%s' % video_id,
|
|
|
|
|
video_id)['psId']
|
|
|
|
|
|
|
|
|
|
return self.url_result('nrk:%s' % nrk_id)
|
|
|
|
|