2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from ..compat
import compat_str
23 class NRKBaseIE(InfoExtractor
):
24 _GEO_COUNTRIES
= ['NO']
25 _CDN_REPL_REGEX
= r
'''(?x)://
27 nrkod\d{1,2}-httpcache0-47115-cacheod0\.dna\.ip-only\.net/47115-cacheod0|
28 nrk-od-no\.telenorcdn\.net|
29 minicdn-od\.nrk\.no/od/nrkhd-osl-rr\.netwerk\.no/no
32 def _extract_nrk_formats(self
, asset_url
, video_id
):
33 if re
.match(r
'https?://[^/]+\.akamaihd\.net/i/', asset_url
):
34 return self
._extract
_akamai
_formats
(asset_url
, video_id
)
35 asset_url
= re
.sub(r
'(?:bw_(?:low|high)=\d+|no_audio_only)&?', '', asset_url
)
36 formats
= self
._extract
_m
3u8_formats
(
37 asset_url
, video_id
, 'mp4', 'm3u8_native', fatal
=False)
38 if not formats
and re
.search(self
._CDN
_REPL
_REGEX
, asset_url
):
39 formats
= self
._extract
_m
3u8_formats
(
40 re
.sub(self
._CDN
_REPL
_REGEX
, '://nrk-od-%02d.akamaized.net/no/' % random
.randint(0, 99), asset_url
),
41 video_id
, 'mp4', 'm3u8_native', fatal
=False)
44 def _raise_error(self
, data
):
46 'ProgramRightsAreNotReady': 'Du kan dessverre ikke se eller høre programmet',
47 'ProgramRightsHasExpired': 'Programmet har gått ut',
48 'NoProgramRights': 'Ikke tilgjengelig',
49 'ProgramIsGeoBlocked': 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
51 message_type
= data
.get('messageType', '')
52 # Can be ProgramIsGeoBlocked or ChannelIsGeoBlocked*
53 if 'IsGeoBlocked' in message_type
or try_get(data
, lambda x
: x
['usageRights']['isGeoBlocked']) is True:
54 self
.raise_geo_restricted(
55 msg
=MESSAGES
.get('ProgramIsGeoBlocked'),
56 countries
=self
._GEO
_COUNTRIES
)
57 message
= data
.get('endUserMessage') or MESSAGES
.get(message_type
, message_type
)
58 raise ExtractorError('%s said: %s' % (self
.IE_NAME
, message
), expected
=True)
60 def _call_api(self
, path
, video_id
, item
=None, note
=None, fatal
=True, query
=None):
61 return self
._download
_json
(
62 urljoin('https://psapi.nrk.no/', path
),
63 video_id
, note
or 'Downloading %s JSON' % item
,
64 fatal
=fatal
, query
=query
,
65 headers
={'Accept-Encoding': 'gzip, deflate, br'}
)
68 class NRKIE(NRKBaseIE
):
74 (?:www\.)?nrk\.no/video/(?:PS\*|[^_]+_)|
75 v8[-.]psapi\.nrk\.no/mediaelement/
83 'url': 'http://www.nrk.no/video/PS*150533',
84 'md5': 'f46be075326e23ad0e524edfcb06aeb6',
88 'title': 'Dompap og andre fugler i Piip-Show',
89 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
94 'url': 'http://www.nrk.no/video/PS*154915',
99 'title': 'Slik høres internett ut når du er blind',
100 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
104 'url': 'nrk:ecc1b952-96dc-4a98-81b9-5296dc7a98d9',
105 'only_matching': True,
107 'url': 'nrk:clip/7707d5a3-ebe7-434a-87d5-a3ebe7a34a70',
108 'only_matching': True,
110 'url': 'https://v8-psapi.nrk.no/mediaelement/ecc1b952-96dc-4a98-81b9-5296dc7a98d9',
111 'only_matching': True,
113 'url': 'https://www.nrk.no/video/dompap-og-andre-fugler-i-piip-show_150533',
114 'only_matching': True,
116 'url': 'https://www.nrk.no/video/humor/kommentatorboksen-reiser-til-sjos_d1fda11f-a4ad-437a-a374-0398bc84e999',
117 'only_matching': True,
120 'url': 'nrk:l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
121 'only_matching': True,
123 'url': 'nrk:podcast/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
124 'only_matching': True,
128 'only_matching': True,
130 'url': 'nrk:clip/150533',
131 'only_matching': True,
134 'url': 'nrk:MDDP12000117',
135 'only_matching': True,
137 'url': 'nrk:program/ENRK10100318',
138 'only_matching': True,
142 'only_matching': True,
144 'url': 'nrk:channel/nrk1',
145 'only_matching': True,
148 def _real_extract(self
, url
):
149 video_id
= self
._match
_id
(url
).split('/')[-1]
151 def call_playback_api(item
, query
=None):
153 return self
._call
_api
(f
'playback/{item}/program/{video_id}', video_id
, item
, query
=query
)
154 except ExtractorError
as e
:
155 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 400:
156 return self
._call
_api
(f
'playback/{item}/{video_id}', video_id
, item
, query
=query
)
159 # known values for preferredCdn: akamai, iponly, minicdn and telenor
160 manifest
= call_playback_api('manifest', {'preferredCdn': 'akamai'}
)
162 video_id
= try_get(manifest
, lambda x
: x
['id'], compat_str
) or video_id
164 if manifest
.get('playability') == 'nonPlayable':
165 self
._raise
_error
(manifest
['nonPlayable'])
167 playable
= manifest
['playable']
170 for asset
in playable
['assets']:
171 if not isinstance(asset
, dict):
173 if asset
.get('encrypted'):
175 format_url
= url_or_none(asset
.get('url'))
178 asset_format
= (asset
.get('format') or '').lower()
179 if asset_format
== 'hls' or determine_ext(format_url
) == 'm3u8':
180 formats
.extend(self
._extract
_nrk
_formats
(format_url
, video_id
))
181 elif asset_format
== 'mp3':
184 'format_id': asset_format
,
187 self
._sort
_formats
(formats
)
189 data
= call_playback_api('metadata')
191 preplay
= data
['preplay']
192 titles
= preplay
['titles']
193 title
= titles
['title']
194 alt_title
= titles
.get('subtitle')
196 description
= try_get(preplay
, lambda x
: x
['description'].replace('\r', '\n'))
197 duration
= parse_duration(playable
.get('duration')) or parse_duration(data
.get('duration'))
200 for image
in try_get(
201 preplay
, lambda x
: x
['poster']['images'], list) or []:
202 if not isinstance(image
, dict):
204 image_url
= url_or_none(image
.get('url'))
209 'width': int_or_none(image
.get('pixelWidth')),
210 'height': int_or_none(image
.get('pixelHeight')),
214 for sub
in try_get(playable
, lambda x
: x
['subtitles'], list) or []:
215 if not isinstance(sub
, dict):
217 sub_url
= url_or_none(sub
.get('webVtt'))
220 sub_key
= str_or_none(sub
.get('language')) or 'nb'
221 sub_type
= str_or_none(sub
.get('type'))
223 sub_key
+= '-%s' % sub_type
224 subtitles
.setdefault(sub_key
, []).append({
229 data
, lambda x
: x
['legalAge']['body']['rating']['code'], compat_str
)
230 # https://en.wikipedia.org/wiki/Norwegian_Media_Authority
235 elif legal_age
.isdigit():
236 age_limit
= int_or_none(legal_age
)
238 is_series
= try_get(data
, lambda x
: x
['_links']['series']['name']) == 'series'
243 'alt_title': alt_title
,
244 'description': description
,
245 'duration': duration
,
246 'thumbnails': thumbnails
,
247 'age_limit': age_limit
,
249 'subtitles': subtitles
,
253 series
= season_id
= season_number
= episode
= episode_number
= None
254 programs
= self
._call
_api
(
255 'programs/%s' % video_id
, video_id
, 'programs', fatal
=False)
256 if programs
and isinstance(programs
, dict):
257 series
= str_or_none(programs
.get('seriesTitle'))
258 season_id
= str_or_none(programs
.get('seasonId'))
259 season_number
= int_or_none(programs
.get('seasonNumber'))
260 episode
= str_or_none(programs
.get('episodeTitle'))
261 episode_number
= int_or_none(programs
.get('episodeNumber'))
265 title
+= ' - %s' % alt_title
266 if not season_number
:
267 season_number
= int_or_none(self
._search
_regex
(
268 r
'Sesong\s+(\d+)', description
or '', 'season number',
271 episode
= alt_title
if is_series
else None
272 if not episode_number
:
273 episode_number
= int_or_none(self
._search
_regex
(
274 r
'^(\d+)\.', episode
or '', 'episode number',
276 if not episode_number
:
277 episode_number
= int_or_none(self
._search
_regex
(
278 r
'\((\d+)\s*:\s*\d+\)', description
or '',
279 'episode number', default
=None))
283 'season_id': season_id
,
284 'season_number': season_number
,
286 'episode_number': episode_number
,
292 class NRKTVIE(InfoExtractor
):
293 IE_DESC
= 'NRK TV and NRK Radio'
294 _EPISODE_RE
= r
'(?P<id>[a-zA-Z]{4}\d{8})'
295 _VALID_URL
= r
'https?://(?:tv|radio)\.nrk(?:super)?\.no/(?:[^/]+/)*%s' % _EPISODE_RE
297 'url': 'https://tv.nrk.no/program/MDDP12000117',
298 'md5': 'c4a5960f1b00b40d47db65c1064e0ab1',
300 'id': 'MDDP12000117',
302 'title': 'Alarm Trolltunga',
303 'description': 'md5:46923a6e6510eefcce23d5ef2a58f2ce',
316 'url': 'https://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
317 'md5': '8d40dab61cea8ab0114e090b029a0565',
319 'id': 'MUHH48000314',
321 'title': '20 spørsmål - 23. mai 2014',
322 'alt_title': '23. mai 2014',
323 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
325 'series': '20 spørsmål',
326 'episode': '23. mai 2014',
330 'url': 'https://tv.nrk.no/program/mdfp15000514',
332 'id': 'MDFP15000514',
334 'title': 'Kunnskapskanalen - Grunnlovsjubiléet - Stor ståhei for ingenting',
335 'description': 'md5:89290c5ccde1b3a24bb8050ab67fe1db',
337 'series': 'Kunnskapskanalen',
338 'episode': 'Grunnlovsjubiléet - Stor ståhei for ingenting',
342 'skip_download': True,
345 # single playlist video
346 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
348 'id': 'MSPO40010515',
350 'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015',
351 'description': 'md5:c03aba1e917561eface5214020551b7a',
355 'skip_download': True,
357 'expected_warnings': ['Failed to download m3u8 information'],
358 'skip': 'particular part is not supported currently',
360 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
362 'id': 'MSPO40010515',
364 'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015',
365 'description': 'md5:c03aba1e917561eface5214020551b7a',
368 'expected_warnings': ['Failed to download m3u8 information'],
369 'skip': 'Ikke tilgjengelig utenfor Norge',
371 'url': 'https://tv.nrk.no/serie/anno/KMTE50001317/sesong-3/episode-13',
373 'id': 'KMTE50001317',
375 'title': 'Anno - 13. episode',
376 'description': 'md5:11d9613661a8dbe6f9bef54e3a4cbbfa',
379 'episode': '13. episode',
381 'episode_number': 13,
385 'skip_download': True,
388 'url': 'https://tv.nrk.no/serie/nytt-paa-nytt/MUHH46000317/27-01-2017',
390 'id': 'MUHH46000317',
392 'title': 'Nytt på Nytt 27.01.2017',
393 'description': 'md5:5358d6388fba0ea6f0b6d11c48b9eb4b',
395 'series': 'Nytt på nytt',
396 'episode': '27.01.2017',
400 'skip_download': True,
402 'skip': 'ProgramRightsHasExpired',
404 'url': 'https://radio.nrk.no/serie/dagsnytt/NPUB21019315/12-07-2015#',
405 'only_matching': True,
407 'url': 'https://tv.nrk.no/serie/lindmo/2018/MUHU11006318/avspiller',
408 'only_matching': True,
410 'url': 'https://radio.nrk.no/serie/dagsnytt/sesong/201507/NPUB21019315',
411 'only_matching': True,
414 def _real_extract(self
, url
):
415 video_id
= self
._match
_id
(url
)
416 return self
.url_result(
417 'nrk:%s' % video_id
, ie
=NRKIE
.ie_key(), video_id
=video_id
)
420 class NRKTVEpisodeIE(InfoExtractor
):
421 _VALID_URL
= r
'https?://tv\.nrk\.no/serie/(?P<id>[^/]+/sesong/(?P<season_number>\d+)/episode/(?P<episode_number>\d+))'
423 'url': 'https://tv.nrk.no/serie/hellums-kro/sesong/1/episode/2',
425 'id': 'MUHH36005220',
427 'title': 'Hellums kro - 2. Kro, krig og kjærlighet',
428 'description': 'md5:ad92ddffc04cea8ce14b415deef81787',
430 'series': 'Hellums kro',
433 'episode': '2. Kro, krig og kjærlighet',
437 'skip_download': True,
440 'url': 'https://tv.nrk.no/serie/backstage/sesong/1/episode/8',
442 'id': 'MSUI14000816',
444 'title': 'Backstage - 8. episode',
445 'description': 'md5:de6ca5d5a2d56849e4021f2bf2850df4',
447 'series': 'Backstage',
450 'episode': '8. episode',
454 'skip_download': True,
456 'skip': 'ProgramRightsHasExpired',
459 def _real_extract(self
, url
):
460 display_id
, season_number
, episode_number
= self
._match
_valid
_url
(url
).groups()
462 webpage
= self
._download
_webpage
(url
, display_id
)
464 info
= self
._search
_json
_ld
(webpage
, display_id
, default
={})
465 nrk_id
= info
.get('@id') or self
._html
_search
_meta
(
466 'nrk:program-id', webpage
, default
=None) or self
._search
_regex
(
467 r
'data-program-id=["\'](%s)' % NRKTVIE._EPISODE_RE, webpage,
469 assert re.match(NRKTVIE._EPISODE_RE, nrk_id)
474 'url
': 'nrk
:%s' % nrk_id,
475 'ie_key
': NRKIE.ie_key(),
476 'season_number
': int(season_number),
477 'episode_number
': int(episode_number),
482 class NRKTVSerieBaseIE(NRKBaseIE):
483 def _extract_entries(self, entry_list):
484 if not isinstance(entry_list, list):
487 for episode in entry_list:
488 nrk_id = episode.get('prfId
') or episode.get('episodeId
')
489 if not nrk_id or not isinstance(nrk_id, compat_str):
491 entries.append(self.url_result(
492 'nrk
:%s' % nrk_id, ie=NRKIE.ie_key(), video_id=nrk_id))
495 _ASSETS_KEYS = ('episodes
', 'instalments
',)
497 def _extract_assets_key(self, embedded):
498 for asset_key in self._ASSETS_KEYS:
499 if embedded.get(asset_key):
503 def _catalog_name(serie_kind):
504 return 'podcast
' if serie_kind in ('podcast
', 'podkast
') else 'series
'
506 def _entries(self, data, display_id):
507 for page_num in itertools.count(1):
508 embedded = data.get('_embedded
') or data
509 if not isinstance(embedded, dict):
511 assets_key = self._extract_assets_key(embedded)
517 (lambda x: x[assets_key]['_embedded
'][assets_key],
518 lambda x: x[assets_key]),
520 for e in self._extract_entries(entries):
523 next_url_path = try_get(
525 (lambda x: x['_links
']['next
']['href
'],
526 lambda x: x['_embedded
'][assets_key]['_links
']['next
']['href
']),
528 if not next_url_path:
530 data = self._call_api(
531 next_url_path, display_id,
532 note='Downloading
%s JSON page
%d' % (assets_key, page_num),
538 class NRKTVSeasonIE(NRKTVSerieBaseIE):
539 _VALID_URL = r'''(?x)
541 (?P<domain>tv|radio)\.nrk\.no/
542 (?P<serie_kind>serie|pod[ck]ast)/
545 (?:sesong/)?(?P<id>\d+)|
546 sesong/(?P<id_2>[^/?#&]+)
550 'url
': 'https
://tv
.nrk
.no
/serie
/backstage
/sesong
/1',
555 'playlist_mincount
': 30,
557 # no /sesong/ in path
558 'url
': 'https
://tv
.nrk
.no
/serie
/lindmo
/2016',
563 'playlist_mincount
': 29,
565 # weird nested _embedded in catalog JSON response
566 'url
': 'https
://radio
.nrk
.no
/serie
/dickie
-dick
-dickens
/sesong
/1',
568 'id': 'dickie
-dick
-dickens
/1',
571 'playlist_mincount
': 11,
573 # 841 entries, multi page
574 'url
': 'https
://radio
.nrk
.no
/serie
/dagsnytt
/sesong
/201509',
576 'id': 'dagsnytt
/201509',
577 'title
': 'September
2015',
579 'playlist_mincount
': 841,
581 # 180 entries, single page
582 'url
': 'https
://tv
.nrk
.no
/serie
/spangas
/sesong
/1',
583 'only_matching
': True,
585 'url
': 'https
://radio
.nrk
.no
/podkast
/hele_historien
/sesong
/diagnose
-kverulant
',
587 'id': 'hele_historien
/diagnose
-kverulant
',
588 'title
': 'Diagnose kverulant
',
590 'playlist_mincount
': 3,
592 'url
': 'https
://radio
.nrk
.no
/podkast
/loerdagsraadet
/sesong
/202101',
593 'only_matching
': True,
597 def suitable(cls, url):
598 return (False if NRKTVIE.suitable(url) or NRKTVEpisodeIE.suitable(url) or NRKRadioPodkastIE.suitable(url)
599 else super(NRKTVSeasonIE, cls).suitable(url))
601 def _real_extract(self, url):
602 mobj = self._match_valid_url(url)
603 domain = mobj.group('domain
')
604 serie_kind = mobj.group('serie_kind
')
605 serie = mobj.group('serie
')
606 season_id = mobj.group('id') or mobj.group('id_2
')
607 display_id = '%s/%s' % (serie, season_id)
609 data = self._call_api(
610 '%s/catalog
/%s/%s/seasons
/%s'
611 % (domain, self._catalog_name(serie_kind), serie, season_id),
612 display_id, 'season
', query={'pageSize': 50})
614 title = try_get(data, lambda x: x['titles
']['title
'], compat_str) or display_id
615 return self.playlist_result(
616 self._entries(data, display_id),
620 class NRKTVSeriesIE(NRKTVSerieBaseIE):
621 _VALID_URL = r'https?
://(?P
<domain
>(?
:tv|radio
)\
.nrk|
(?
:tv\
.)?nrksuper
)\
.no
/(?P
<serie_kind
>serie|pod
[ck
]ast
)/(?P
<id>[^
/]+)'
623 # new layout, instalments
624 'url
': 'https
://tv
.nrk
.no
/serie
/groenn
-glede
',
626 'id': 'groenn
-glede
',
627 'title
': 'Grønn glede
',
628 'description
': 'md5
:7576e92ae7f65da6993cf90ee29e4608
',
630 'playlist_mincount
': 90,
632 # new layout, instalments, more entries
633 'url
': 'https
://tv
.nrk
.no
/serie
/lindmo
',
634 'only_matching
': True,
636 'url
': 'https
://tv
.nrk
.no
/serie
/blank
',
640 'description
': 'md5
:7664b4e7e77dc6810cd3bca367c25b6e
',
642 'playlist_mincount
': 30,
644 # new layout, seasons
645 'url
': 'https
://tv
.nrk
.no
/serie
/backstage
',
648 'title
': 'Backstage
',
649 'description
': 'md5
:63692ceb96813d9a207e9910483d948b
',
651 'playlist_mincount
': 60,
654 'url
': 'https
://tv
.nrksuper
.no
/serie
/labyrint
',
658 'description
': 'I Daidalos sin undersjøiske Labyrint venter spennende oppgaver
, skumle robotskapninger og slim
.',
660 'playlist_mincount
': 3,
662 'url
': 'https
://tv
.nrk
.no
/serie
/broedrene
-dal
-og
-spektralsteinene
',
663 'only_matching
': True,
665 'url
': 'https
://tv
.nrk
.no
/serie
/saving
-the
-human
-race
',
666 'only_matching
': True,
668 'url
': 'https
://tv
.nrk
.no
/serie
/postmann
-pat
',
669 'only_matching
': True,
671 'url
': 'https
://radio
.nrk
.no
/serie
/dickie
-dick
-dickens
',
673 'id': 'dickie
-dick
-dickens
',
674 'title
': 'Dickie Dick Dickens
',
675 'description
': 'md5
:19e67411ffe57f7dce08a943d7a0b91f
',
677 'playlist_mincount
': 8,
679 'url
': 'https
://nrksuper
.no
/serie
/labyrint
',
680 'only_matching
': True,
682 'url
': 'https
://radio
.nrk
.no
/podkast
/ulrikkes_univers
',
684 'id': 'ulrikkes_univers
',
686 'playlist_mincount
': 10,
688 'url
': 'https
://radio
.nrk
.no
/podkast
/ulrikkes_univers
/nrkno
-poddkast
-26588-134079-05042018030000',
689 'only_matching
': True,
693 def suitable(cls, url):
695 False if any(ie.suitable(url)
696 for ie in (NRKTVIE, NRKTVEpisodeIE, NRKRadioPodkastIE, NRKTVSeasonIE))
697 else super(NRKTVSeriesIE, cls).suitable(url))
699 def _real_extract(self, url):
700 site, serie_kind, series_id = self._match_valid_url(url).groups()
701 is_radio = site == 'radio
.nrk
'
702 domain = 'radio
' if is_radio else 'tv
'
704 size_prefix = 'p
' if is_radio else 'embeddedInstalmentsP
'
705 series = self._call_api(
707 % (domain, self._catalog_name(serie_kind), series_id),
708 series_id, 'serie
', query={size_prefix + 'ageSize': 50})
709 titles = try_get(series, [
710 lambda x: x['titles
'],
711 lambda x: x[x['type']]['titles
'],
712 lambda x: x[x['seriesType
']]['titles
'],
716 entries.extend(self._entries(series, series_id))
717 embedded = series.get('_embedded
') or {}
718 linked_seasons = try_get(series, lambda x: x['_links
']['seasons
']) or []
719 embedded_seasons = embedded.get('seasons
') or []
720 if len(linked_seasons) > len(embedded_seasons):
721 for season in linked_seasons:
722 season_url = urljoin(url, season.get('href
'))
724 season_name = season.get('name
')
725 if season_name and isinstance(season_name, compat_str):
726 season_url = 'https
://%s.nrk
.no
/serie
/%s/sesong
/%s' % (domain, series_id, season_name)
728 entries.append(self.url_result(
729 season_url, ie=NRKTVSeasonIE.ie_key(),
730 video_title=season.get('title
')))
732 for season in embedded_seasons:
733 entries.extend(self._entries(season, series_id))
734 entries.extend(self._entries(
735 embedded.get('extraMaterial
') or {}, series_id))
737 return self.playlist_result(
738 entries, series_id, titles.get('title
'), titles.get('subtitle
'))
741 class NRKTVDirekteIE(NRKTVIE):
742 IE_DESC = 'NRK TV Direkte
and NRK Radio Direkte
'
743 _VALID_URL = r'https?
://(?
:tv|radio
)\
.nrk\
.no
/direkte
/(?P
<id>[^
/?
#&]+)'
746 'url': 'https://tv.nrk.no/direkte/nrk1',
747 'only_matching': True,
749 'url': 'https://radio.nrk.no/direkte/p1_oslo_akershus',
750 'only_matching': True,
754 class NRKRadioPodkastIE(InfoExtractor
):
755 _VALID_URL
= r
'https?://radio\.nrk\.no/pod[ck]ast/(?:[^/]+/)+(?P<id>l_[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})'
758 'url': 'https://radio.nrk.no/podkast/ulrikkes_univers/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
759 'md5': '8d40dab61cea8ab0114e090b029a0565',
761 'id': 'MUHH48000314AA',
763 'title': '20 spørsmål 23.05.2014',
764 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
766 'series': '20 spørsmål',
767 'episode': '23.05.2014',
770 'url': 'https://radio.nrk.no/podcast/ulrikkes_univers/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
771 'only_matching': True,
773 'url': 'https://radio.nrk.no/podkast/ulrikkes_univers/sesong/1/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
774 'only_matching': True,
776 'url': 'https://radio.nrk.no/podkast/hele_historien/sesong/bortfoert-i-bergen/l_774d1a2c-7aa7-4965-8d1a-2c7aa7d9652c',
777 'only_matching': True,
780 def _real_extract(self
, url
):
781 video_id
= self
._match
_id
(url
)
782 return self
.url_result(
783 'nrk:%s' % video_id
, ie
=NRKIE
.ie_key(), video_id
=video_id
)
786 class NRKPlaylistBaseIE(InfoExtractor
):
787 def _extract_description(self
, webpage
):
790 def _real_extract(self
, url
):
791 playlist_id
= self
._match
_id
(url
)
793 webpage
= self
._download
_webpage
(url
, playlist_id
)
796 self
.url_result('nrk:%s' % video_id
, NRKIE
.ie_key())
797 for video_id
in re
.findall(self
._ITEM
_RE
, webpage
)
800 playlist_title
= self
. _extract_title(webpage
)
801 playlist_description
= self
._extract
_description
(webpage
)
803 return self
.playlist_result(
804 entries
, playlist_id
, playlist_title
, playlist_description
)
807 class NRKPlaylistIE(NRKPlaylistBaseIE
):
808 _VALID_URL
= r
'https?://(?:www\.)?nrk\.no/(?!video|skole)(?:[^/]+/)+(?P<id>[^/]+)'
809 _ITEM_RE
= r
'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"'
811 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
813 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
814 'title': 'Gjenopplev den historiske solformørkelsen',
815 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
819 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
821 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
822 'title': 'Rivertonprisen til Karin Fossum',
823 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
828 def _extract_title(self
, webpage
):
829 return self
._og
_search
_title
(webpage
, fatal
=False)
831 def _extract_description(self
, webpage
):
832 return self
._og
_search
_description
(webpage
)
835 class NRKTVEpisodesIE(NRKPlaylistBaseIE
):
836 _VALID_URL
= r
'https?://tv\.nrk\.no/program/[Ee]pisodes/[^/]+/(?P<id>\d+)'
837 _ITEM_RE
= r
'data-episode=["\']%s' % NRKTVIE._EPISODE_RE
839 'url
': 'https
://tv
.nrk
.no
/program
/episodes
/nytt
-paa
-nytt
/69031',
842 'title
': 'Nytt på nytt
, sesong
: 201210',
847 def _extract_title(self, webpage):
848 return self._html_search_regex(
849 r'<h1
>([^
<]+)</h1
>', webpage, 'title
', fatal=False)
852 class NRKSkoleIE(InfoExtractor):
853 IE_DESC = 'NRK Skole
'
854 _VALID_URL = r'https?
://(?
:www\
.)?nrk\
.no
/skole
/?
\?.*\bmediaId
=(?P
<id>\d
+)'
857 'url
': 'https
://www
.nrk
.no
/skole
/?page
=search
&q
=&mediaId
=14099',
858 'md5
': '18c12c3d071953c3bf8d54ef6b2587b7
',
862 'title
': 'Genetikk og eneggede tvillinger
',
863 'description
': 'md5
:3aca25dcf38ec30f0363428d2b265f8d
',
867 'url
': 'https
://www
.nrk
.no
/skole
/?page
=objectives
&subject
=naturfag
&objective
=K15114
&mediaId
=19355',
868 'only_matching
': True,
871 def _real_extract(self, url):
872 video_id = self._match_id(url)
874 nrk_id = self._download_json(
875 'https
://nrkno
-skole
-prod
.kube
.nrk
.no
/skole
/api
/media
/%s' % video_id,
878 return self.url_result('nrk
:%s' % nrk_id)