5 from .common
import InfoExtractor
6 from ..networking
.exceptions
import HTTPError
20 class NRKBaseIE(InfoExtractor
):
21 _GEO_COUNTRIES
= ['NO']
22 _CDN_REPL_REGEX
= r
'''(?x)://
24 nrkod\d{1,2}-httpcache0-47115-cacheod0\.dna\.ip-only\.net/47115-cacheod0|
25 nrk-od-no\.telenorcdn\.net|
26 minicdn-od\.nrk\.no/od/nrkhd-osl-rr\.netwerk\.no/no
29 def _extract_nrk_formats(self
, asset_url
, video_id
):
30 if re
.match(r
'https?://[^/]+\.akamaihd\.net/i/', asset_url
):
31 return self
._extract
_akamai
_formats
(asset_url
, video_id
)
32 asset_url
= re
.sub(r
'(?:bw_(?:low|high)=\d+|no_audio_only)&?', '', asset_url
)
33 formats
= self
._extract
_m
3u8_formats
(
34 asset_url
, video_id
, 'mp4', 'm3u8_native', fatal
=False)
35 if not formats
and re
.search(self
._CDN
_REPL
_REGEX
, asset_url
):
36 formats
= self
._extract
_m
3u8_formats
(
37 re
.sub(self
._CDN
_REPL
_REGEX
, '://nrk-od-%02d.akamaized.net/no/' % random
.randint(0, 99), asset_url
),
38 video_id
, 'mp4', 'm3u8_native', fatal
=False)
41 def _raise_error(self
, data
):
43 'ProgramRightsAreNotReady': 'Du kan dessverre ikke se eller høre programmet',
44 'ProgramRightsHasExpired': 'Programmet har gått ut',
45 'NoProgramRights': 'Ikke tilgjengelig',
46 'ProgramIsGeoBlocked': 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
48 message_type
= data
.get('messageType', '')
49 # Can be ProgramIsGeoBlocked or ChannelIsGeoBlocked*
50 if 'IsGeoBlocked' in message_type
or try_get(data
, lambda x
: x
['usageRights']['isGeoBlocked']) is True:
51 self
.raise_geo_restricted(
52 msg
=MESSAGES
.get('ProgramIsGeoBlocked'),
53 countries
=self
._GEO
_COUNTRIES
)
54 message
= data
.get('endUserMessage') or MESSAGES
.get(message_type
, message_type
)
55 raise ExtractorError(f
'{self.IE_NAME} said: {message}', expected
=True)
57 def _call_api(self
, path
, video_id
, item
=None, note
=None, fatal
=True, query
=None):
58 return self
._download
_json
(
59 urljoin('https://psapi.nrk.no/', path
),
60 video_id
, note
or f
'Downloading {item} JSON',
61 fatal
=fatal
, query
=query
)
64 class NRKIE(NRKBaseIE
):
70 (?:www\.)?nrk\.no/video/(?:PS\*|[^_]+_)|
71 v8[-.]psapi\.nrk\.no/mediaelement/
79 'url': 'http://www.nrk.no/video/PS*150533',
80 'md5': 'f46be075326e23ad0e524edfcb06aeb6',
84 'title': 'Dompap og andre fugler i Piip-Show',
85 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
90 'url': 'http://www.nrk.no/video/PS*154915',
95 'title': 'Slik høres internett ut når du er blind',
96 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
100 'url': 'nrk:ecc1b952-96dc-4a98-81b9-5296dc7a98d9',
101 'only_matching': True,
103 'url': 'nrk:clip/7707d5a3-ebe7-434a-87d5-a3ebe7a34a70',
104 'only_matching': True,
106 'url': 'https://v8-psapi.nrk.no/mediaelement/ecc1b952-96dc-4a98-81b9-5296dc7a98d9',
107 'only_matching': True,
109 'url': 'https://www.nrk.no/video/dompap-og-andre-fugler-i-piip-show_150533',
110 'only_matching': True,
112 'url': 'https://www.nrk.no/video/humor/kommentatorboksen-reiser-til-sjos_d1fda11f-a4ad-437a-a374-0398bc84e999',
113 'only_matching': True,
116 'url': 'nrk:l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
117 'only_matching': True,
119 'url': 'nrk:podcast/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
120 'only_matching': True,
124 'only_matching': True,
126 'url': 'nrk:clip/150533',
127 'only_matching': True,
130 'url': 'nrk:MDDP12000117',
131 'only_matching': True,
133 'url': 'nrk:program/ENRK10100318',
134 'only_matching': True,
138 'only_matching': True,
140 'url': 'nrk:channel/nrk1',
141 'only_matching': True,
144 def _real_extract(self
, url
):
145 video_id
= self
._match
_id
(url
).split('/')[-1]
147 def call_playback_api(item
, query
=None):
149 return self
._call
_api
(f
'playback/{item}/program/{video_id}', video_id
, item
, query
=query
)
150 except ExtractorError
as e
:
151 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== 400:
152 return self
._call
_api
(f
'playback/{item}/{video_id}', video_id
, item
, query
=query
)
155 # known values for preferredCdn: akamai, iponly, minicdn and telenor
156 manifest
= call_playback_api('manifest', {'preferredCdn': 'akamai'})
158 video_id
= try_get(manifest
, lambda x
: x
['id'], str) or video_id
160 if manifest
.get('playability') == 'nonPlayable':
161 self
._raise
_error
(manifest
['nonPlayable'])
163 playable
= manifest
['playable']
166 for asset
in playable
['assets']:
167 if not isinstance(asset
, dict):
169 if asset
.get('encrypted'):
171 format_url
= url_or_none(asset
.get('url'))
174 asset_format
= (asset
.get('format') or '').lower()
175 if asset_format
== 'hls' or determine_ext(format_url
) == 'm3u8':
176 formats
.extend(self
._extract
_nrk
_formats
(format_url
, video_id
))
177 elif asset_format
== 'mp3':
180 'format_id': asset_format
,
184 data
= call_playback_api('metadata')
186 preplay
= data
['preplay']
187 titles
= preplay
['titles']
188 title
= titles
['title']
189 alt_title
= titles
.get('subtitle')
191 description
= try_get(preplay
, lambda x
: x
['description'].replace('\r', '\n'))
192 duration
= parse_duration(playable
.get('duration')) or parse_duration(data
.get('duration'))
195 for image
in try_get(
196 preplay
, lambda x
: x
['poster']['images'], list) or []:
197 if not isinstance(image
, dict):
199 image_url
= url_or_none(image
.get('url'))
204 'width': int_or_none(image
.get('pixelWidth')),
205 'height': int_or_none(image
.get('pixelHeight')),
209 for sub
in try_get(playable
, lambda x
: x
['subtitles'], list) or []:
210 if not isinstance(sub
, dict):
212 sub_url
= url_or_none(sub
.get('webVtt'))
215 sub_key
= str_or_none(sub
.get('language')) or 'nb'
216 sub_type
= str_or_none(sub
.get('type'))
218 sub_key
+= f
'-{sub_type}'
219 subtitles
.setdefault(sub_key
, []).append({
224 data
, lambda x
: x
['legalAge']['body']['rating']['code'], str)
225 # https://en.wikipedia.org/wiki/Norwegian_Media_Authority
230 elif legal_age
.isdigit():
231 age_limit
= int_or_none(legal_age
)
233 is_series
= try_get(data
, lambda x
: x
['_links']['series']['name']) == 'series'
238 'alt_title': alt_title
,
239 'description': description
,
240 'duration': duration
,
241 'thumbnails': thumbnails
,
242 'age_limit': age_limit
,
244 'subtitles': subtitles
,
245 'timestamp': parse_iso8601(try_get(manifest
, lambda x
: x
['availability']['onDemand']['from'], str)),
249 series
= season_id
= season_number
= episode
= episode_number
= None
250 programs
= self
._call
_api
(
251 f
'programs/{video_id}', video_id
, 'programs', fatal
=False)
252 if programs
and isinstance(programs
, dict):
253 series
= str_or_none(programs
.get('seriesTitle'))
254 season_id
= str_or_none(programs
.get('seasonId'))
255 season_number
= int_or_none(programs
.get('seasonNumber'))
256 episode
= str_or_none(programs
.get('episodeTitle'))
257 episode_number
= int_or_none(programs
.get('episodeNumber'))
261 title
+= f
' - {alt_title}'
262 if not season_number
:
263 season_number
= int_or_none(self
._search
_regex
(
264 r
'Sesong\s+(\d+)', description
or '', 'season number',
267 episode
= alt_title
if is_series
else None
268 if not episode_number
:
269 episode_number
= int_or_none(self
._search
_regex
(
270 r
'^(\d+)\.', episode
or '', 'episode number',
272 if not episode_number
:
273 episode_number
= int_or_none(self
._search
_regex
(
274 r
'\((\d+)\s*:\s*\d+\)', description
or '',
275 'episode number', default
=None))
279 'season_id': season_id
,
280 'season_number': season_number
,
282 'episode_number': episode_number
,
288 class NRKTVIE(InfoExtractor
):
289 IE_DESC
= 'NRK TV and NRK Radio'
290 _EPISODE_RE
= r
'(?P<id>[a-zA-Z]{4}\d{8})'
291 _VALID_URL
= rf
'https?://(?:tv|radio)\.nrk(?:super)?\.no/(?:[^/]+/)*{_EPISODE_RE}'
293 'url': 'https://tv.nrk.no/program/MDDP12000117',
294 'md5': 'c4a5960f1b00b40d47db65c1064e0ab1',
296 'id': 'MDDP12000117',
298 'title': 'Alarm Trolltunga',
299 'description': 'md5:46923a6e6510eefcce23d5ef2a58f2ce',
312 'url': 'https://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
313 'md5': '8d40dab61cea8ab0114e090b029a0565',
315 'id': 'MUHH48000314',
317 'title': '20 spørsmål - 23. mai 2014',
318 'alt_title': '23. mai 2014',
319 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
321 'series': '20 spørsmål',
322 'episode': '23. mai 2014',
326 'url': 'https://tv.nrk.no/program/mdfp15000514',
328 'id': 'MDFP15000514',
330 'title': 'Kunnskapskanalen - Grunnlovsjubiléet - Stor ståhei for ingenting',
331 'description': 'md5:89290c5ccde1b3a24bb8050ab67fe1db',
333 'series': 'Kunnskapskanalen',
334 'episode': 'Grunnlovsjubiléet - Stor ståhei for ingenting',
338 'skip_download': True,
341 # single playlist video
342 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
344 'id': 'MSPO40010515',
346 'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015',
347 'description': 'md5:c03aba1e917561eface5214020551b7a',
351 'skip_download': True,
353 'expected_warnings': ['Failed to download m3u8 information'],
354 'skip': 'particular part is not supported currently',
356 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
358 'id': 'MSPO40010515',
360 'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015',
361 'description': 'md5:c03aba1e917561eface5214020551b7a',
364 'expected_warnings': ['Failed to download m3u8 information'],
365 'skip': 'Ikke tilgjengelig utenfor Norge',
367 'url': 'https://tv.nrk.no/serie/anno/KMTE50001317/sesong-3/episode-13',
369 'id': 'KMTE50001317',
371 'title': 'Anno - 13. episode',
372 'description': 'md5:11d9613661a8dbe6f9bef54e3a4cbbfa',
375 'episode': '13. episode',
377 'episode_number': 13,
381 'skip_download': True,
384 'url': 'https://tv.nrk.no/serie/nytt-paa-nytt/MUHH46000317/27-01-2017',
386 'id': 'MUHH46000317',
388 'title': 'Nytt på Nytt 27.01.2017',
389 'description': 'md5:5358d6388fba0ea6f0b6d11c48b9eb4b',
391 'series': 'Nytt på nytt',
392 'episode': '27.01.2017',
396 'skip_download': True,
398 'skip': 'ProgramRightsHasExpired',
400 'url': 'https://radio.nrk.no/serie/dagsnytt/NPUB21019315/12-07-2015#',
401 'only_matching': True,
403 'url': 'https://tv.nrk.no/serie/lindmo/2018/MUHU11006318/avspiller',
404 'only_matching': True,
406 'url': 'https://radio.nrk.no/serie/dagsnytt/sesong/201507/NPUB21019315',
407 'only_matching': True,
410 def _real_extract(self
, url
):
411 video_id
= self
._match
_id
(url
)
412 return self
.url_result(
413 f
'nrk:{video_id}', ie
=NRKIE
.ie_key(), video_id
=video_id
)
416 class NRKTVEpisodeIE(InfoExtractor
):
417 _VALID_URL
= r
'https?://tv\.nrk\.no/serie/(?P<id>[^/]+/sesong/(?P<season_number>\d+)/episode/(?P<episode_number>\d+))'
419 'url': 'https://tv.nrk.no/serie/hellums-kro/sesong/1/episode/2',
421 'id': 'MUHH36005220',
423 'title': 'Hellums kro - 2. Kro, krig og kjærlighet',
424 'description': 'md5:ad92ddffc04cea8ce14b415deef81787',
426 'series': 'Hellums kro',
429 'episode': '2. Kro, krig og kjærlighet',
433 'skip_download': True,
436 'url': 'https://tv.nrk.no/serie/backstage/sesong/1/episode/8',
438 'id': 'MSUI14000816',
440 'title': 'Backstage - 8. episode',
441 'description': 'md5:de6ca5d5a2d56849e4021f2bf2850df4',
443 'series': 'Backstage',
446 'episode': '8. episode',
450 'skip_download': True,
452 'skip': 'ProgramRightsHasExpired',
455 def _real_extract(self
, url
):
456 display_id
, season_number
, episode_number
= self
._match
_valid
_url
(url
).groups()
458 webpage
= self
._download
_webpage
(url
, display_id
)
460 info
= self
._search
_json
_ld
(webpage
, display_id
, default
={})
461 nrk_id
= info
.get('@id') or self
._html
_search
_meta
(
462 'nrk:program-id', webpage
, default
=None) or self
._search
_regex
(
463 rf
'data-program-id=["\']({NRKTVIE._EPISODE_RE})', webpage
,
465 assert re
.match(NRKTVIE
._EPISODE
_RE
, nrk_id
)
470 'url': f
'nrk:{nrk_id}',
471 'ie_key': NRKIE
.ie_key(),
472 'season_number': int(season_number
),
473 'episode_number': int(episode_number
),
478 class NRKTVSerieBaseIE(NRKBaseIE
):
479 def _extract_entries(self
, entry_list
):
480 if not isinstance(entry_list
, list):
483 for episode
in entry_list
:
484 nrk_id
= episode
.get('prfId') or episode
.get('episodeId')
485 if not nrk_id
or not isinstance(nrk_id
, str):
487 entries
.append(self
.url_result(
488 f
'nrk:{nrk_id}', ie
=NRKIE
.ie_key(), video_id
=nrk_id
))
491 _ASSETS_KEYS
= ('episodes', 'instalments')
493 def _extract_assets_key(self
, embedded
):
494 for asset_key
in self
._ASSETS
_KEYS
:
495 if embedded
.get(asset_key
):
499 def _catalog_name(serie_kind
):
500 return 'podcast' if serie_kind
in ('podcast', 'podkast') else 'series'
502 def _entries(self
, data
, display_id
):
503 for page_num
in itertools
.count(1):
504 embedded
= data
.get('_embedded') or data
505 if not isinstance(embedded
, dict):
507 assets_key
= self
._extract
_assets
_key
(embedded
)
513 (lambda x
: x
[assets_key
]['_embedded'][assets_key
],
514 lambda x
: x
[assets_key
]),
516 yield from self
._extract
_entries
(entries
)
518 next_url_path
= try_get(
520 (lambda x
: x
['_links']['next']['href'],
521 lambda x
: x
['_embedded'][assets_key
]['_links']['next']['href']),
523 if not next_url_path
:
525 data
= self
._call
_api
(
526 next_url_path
, display_id
,
527 note
=f
'Downloading {assets_key} JSON page {page_num}',
533 class NRKTVSeasonIE(NRKTVSerieBaseIE
):
534 _VALID_URL
= r
'''(?x)
536 (?P<domain>tv|radio)\.nrk\.no/
537 (?P<serie_kind>serie|pod[ck]ast)/
540 (?:sesong/)?(?P<id>\d+)|
541 sesong/(?P<id_2>[^/?#&]+)
545 'url': 'https://tv.nrk.no/serie/backstage/sesong/1',
550 'playlist_mincount': 30,
552 # no /sesong/ in path
553 'url': 'https://tv.nrk.no/serie/lindmo/2016',
558 'playlist_mincount': 29,
560 # weird nested _embedded in catalog JSON response
561 'url': 'https://radio.nrk.no/serie/dickie-dick-dickens/sesong/1',
563 'id': 'dickie-dick-dickens/1',
566 'playlist_mincount': 11,
568 # 841 entries, multi page
569 'url': 'https://radio.nrk.no/serie/dagsnytt/sesong/201509',
571 'id': 'dagsnytt/201509',
572 'title': 'September 2015',
574 'playlist_mincount': 841,
576 # 180 entries, single page
577 'url': 'https://tv.nrk.no/serie/spangas/sesong/1',
578 'only_matching': True,
580 'url': 'https://radio.nrk.no/podkast/hele_historien/sesong/diagnose-kverulant',
582 'id': 'hele_historien/diagnose-kverulant',
583 'title': 'Diagnose kverulant',
585 'playlist_mincount': 3,
587 'url': 'https://radio.nrk.no/podkast/loerdagsraadet/sesong/202101',
588 'only_matching': True,
592 def suitable(cls
, url
):
593 return (False if NRKTVIE
.suitable(url
) or NRKTVEpisodeIE
.suitable(url
) or NRKRadioPodkastIE
.suitable(url
)
594 else super().suitable(url
))
596 def _real_extract(self
, url
):
597 mobj
= self
._match
_valid
_url
(url
)
598 domain
= mobj
.group('domain')
599 serie_kind
= mobj
.group('serie_kind')
600 serie
= mobj
.group('serie')
601 season_id
= mobj
.group('id') or mobj
.group('id_2')
602 display_id
= f
'{serie}/{season_id}'
604 data
= self
._call
_api
(
605 f
'{domain}/catalog/{self._catalog_name(serie_kind)}/{serie}/seasons/{season_id}',
606 display_id
, 'season', query
={'pageSize': 50})
608 title
= try_get(data
, lambda x
: x
['titles']['title'], str) or display_id
609 return self
.playlist_result(
610 self
._entries
(data
, display_id
),
614 class NRKTVSeriesIE(NRKTVSerieBaseIE
):
615 _VALID_URL
= r
'https?://(?P<domain>(?:tv|radio)\.nrk|(?:tv\.)?nrksuper)\.no/(?P<serie_kind>serie|pod[ck]ast)/(?P<id>[^/]+)'
617 # new layout, instalments
618 'url': 'https://tv.nrk.no/serie/groenn-glede',
620 'id': 'groenn-glede',
621 'title': 'Grønn glede',
622 'description': 'md5:7576e92ae7f65da6993cf90ee29e4608',
624 'playlist_mincount': 90,
626 # new layout, instalments, more entries
627 'url': 'https://tv.nrk.no/serie/lindmo',
628 'only_matching': True,
630 'url': 'https://tv.nrk.no/serie/blank',
634 'description': 'md5:7664b4e7e77dc6810cd3bca367c25b6e',
636 'playlist_mincount': 30,
638 # new layout, seasons
639 'url': 'https://tv.nrk.no/serie/backstage',
642 'title': 'Backstage',
643 'description': 'md5:63692ceb96813d9a207e9910483d948b',
645 'playlist_mincount': 60,
648 'url': 'https://tv.nrksuper.no/serie/labyrint',
652 'description': 'I Daidalos sin undersjøiske Labyrint venter spennende oppgaver, skumle robotskapninger og slim.',
654 'playlist_mincount': 3,
656 'url': 'https://tv.nrk.no/serie/broedrene-dal-og-spektralsteinene',
657 'only_matching': True,
659 'url': 'https://tv.nrk.no/serie/saving-the-human-race',
660 'only_matching': True,
662 'url': 'https://tv.nrk.no/serie/postmann-pat',
663 'only_matching': True,
665 'url': 'https://radio.nrk.no/serie/dickie-dick-dickens',
667 'id': 'dickie-dick-dickens',
668 'title': 'Dickie Dick Dickens',
669 'description': 'md5:19e67411ffe57f7dce08a943d7a0b91f',
671 'playlist_mincount': 8,
673 'url': 'https://nrksuper.no/serie/labyrint',
674 'only_matching': True,
676 'url': 'https://radio.nrk.no/podkast/ulrikkes_univers',
678 'id': 'ulrikkes_univers',
680 'playlist_mincount': 10,
682 'url': 'https://radio.nrk.no/podkast/ulrikkes_univers/nrkno-poddkast-26588-134079-05042018030000',
683 'only_matching': True,
687 def suitable(cls
, url
):
689 False if any(ie
.suitable(url
)
690 for ie
in (NRKTVIE
, NRKTVEpisodeIE
, NRKRadioPodkastIE
, NRKTVSeasonIE
))
691 else super().suitable(url
))
693 def _real_extract(self
, url
):
694 site
, serie_kind
, series_id
= self
._match
_valid
_url
(url
).groups()
695 is_radio
= site
== 'radio.nrk'
696 domain
= 'radio' if is_radio
else 'tv'
698 size_prefix
= 'p' if is_radio
else 'embeddedInstalmentsP'
699 series
= self
._call
_api
(
700 f
'{domain}/catalog/{self._catalog_name(serie_kind)}/{series_id}',
701 series_id
, 'serie', query
={size_prefix
+ 'ageSize': 50})
702 titles
= try_get(series
, [
703 lambda x
: x
['titles'],
704 lambda x
: x
[x
['type']]['titles'],
705 lambda x
: x
[x
['seriesType']]['titles'],
709 entries
.extend(self
._entries
(series
, series_id
))
710 embedded
= series
.get('_embedded') or {}
711 linked_seasons
= try_get(series
, lambda x
: x
['_links']['seasons']) or []
712 embedded_seasons
= embedded
.get('seasons') or []
713 if len(linked_seasons
) > len(embedded_seasons
):
714 for season
in linked_seasons
:
715 season_url
= urljoin(url
, season
.get('href'))
717 season_name
= season
.get('name')
718 if season_name
and isinstance(season_name
, str):
719 season_url
= f
'https://{domain}.nrk.no/serie/{series_id}/sesong/{season_name}'
721 entries
.append(self
.url_result(
722 season_url
, ie
=NRKTVSeasonIE
.ie_key(),
723 video_title
=season
.get('title')))
725 for season
in embedded_seasons
:
726 entries
.extend(self
._entries
(season
, series_id
))
727 entries
.extend(self
._entries
(
728 embedded
.get('extraMaterial') or {}, series_id
))
730 return self
.playlist_result(
731 entries
, series_id
, titles
.get('title'), titles
.get('subtitle'))
734 class NRKTVDirekteIE(NRKTVIE
): # XXX: Do not subclass from concrete IE
735 IE_DESC
= 'NRK TV Direkte and NRK Radio Direkte'
736 _VALID_URL
= r
'https?://(?:tv|radio)\.nrk\.no/direkte/(?P<id>[^/?#&]+)'
739 'url': 'https://tv.nrk.no/direkte/nrk1',
740 'only_matching': True,
742 'url': 'https://radio.nrk.no/direkte/p1_oslo_akershus',
743 'only_matching': True,
747 class NRKRadioPodkastIE(InfoExtractor
):
748 _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})'
751 'url': 'https://radio.nrk.no/podkast/ulrikkes_univers/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
752 'md5': '8d40dab61cea8ab0114e090b029a0565',
754 'id': 'MUHH48000314AA',
756 'title': '20 spørsmål 23.05.2014',
757 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
759 'series': '20 spørsmål',
760 'episode': '23.05.2014',
763 'url': 'https://radio.nrk.no/podcast/ulrikkes_univers/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
764 'only_matching': True,
766 'url': 'https://radio.nrk.no/podkast/ulrikkes_univers/sesong/1/l_96f4f1b0-de54-4e6a-b4f1-b0de54fe6af8',
767 'only_matching': True,
769 'url': 'https://radio.nrk.no/podkast/hele_historien/sesong/bortfoert-i-bergen/l_774d1a2c-7aa7-4965-8d1a-2c7aa7d9652c',
770 'only_matching': True,
773 def _real_extract(self
, url
):
774 video_id
= self
._match
_id
(url
)
775 return self
.url_result(
776 f
'nrk:{video_id}', ie
=NRKIE
.ie_key(), video_id
=video_id
)
779 class NRKPlaylistBaseIE(InfoExtractor
):
780 def _extract_description(self
, webpage
):
783 def _real_extract(self
, url
):
784 playlist_id
= self
._match
_id
(url
)
786 webpage
= self
._download
_webpage
(url
, playlist_id
)
789 self
.url_result(f
'nrk:{video_id}', NRKIE
.ie_key())
790 for video_id
in re
.findall(self
._ITEM
_RE
, webpage
)
793 playlist_title
= self
._extract
_title
(webpage
)
794 playlist_description
= self
._extract
_description
(webpage
)
796 return self
.playlist_result(
797 entries
, playlist_id
, playlist_title
, playlist_description
)
800 class NRKPlaylistIE(NRKPlaylistBaseIE
):
801 _VALID_URL
= r
'https?://(?:www\.)?nrk\.no/(?!video|skole)(?:[^/]+/)+(?P<id>[^/]+)'
802 _ITEM_RE
= r
'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"'
804 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
806 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
807 'title': 'Gjenopplev den historiske solformørkelsen',
808 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
812 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
814 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
815 'title': 'Rivertonprisen til Karin Fossum',
816 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
821 def _extract_title(self
, webpage
):
822 return self
._og
_search
_title
(webpage
, fatal
=False)
824 def _extract_description(self
, webpage
):
825 return self
._og
_search
_description
(webpage
)
828 class NRKTVEpisodesIE(NRKPlaylistBaseIE
):
829 _VALID_URL
= r
'https?://tv\.nrk\.no/program/[Ee]pisodes/[^/]+/(?P<id>\d+)'
830 _ITEM_RE
= rf
'data-episode=["\']{NRKTVIE._EPISODE_RE}'
832 'url': 'https://tv.nrk.no/program/episodes/nytt-paa-nytt/69031',
835 'title': 'Nytt på nytt, sesong: 201210',
840 def _extract_title(self
, webpage
):
841 return self
._html
_search
_regex
(
842 r
'<h1>([^<]+)</h1>', webpage
, 'title', fatal
=False)
845 class NRKSkoleIE(InfoExtractor
):
846 IE_DESC
= 'NRK Skole'
847 _VALID_URL
= r
'https?://(?:www\.)?nrk\.no/skole/?\?.*\bmediaId=(?P<id>\d+)'
850 'url': 'https://www.nrk.no/skole/?page=search&q=&mediaId=14099',
851 'md5': '18c12c3d071953c3bf8d54ef6b2587b7',
855 'title': 'Genetikk og eneggede tvillinger',
856 'description': 'md5:3aca25dcf38ec30f0363428d2b265f8d',
860 'url': 'https://www.nrk.no/skole/?page=objectives&subject=naturfag&objective=K15114&mediaId=19355',
861 'only_matching': True,
864 def _real_extract(self
, url
):
865 video_id
= self
._match
_id
(url
)
867 nrk_id
= self
._download
_json
(
868 f
'https://nrkno-skole-prod.kube.nrk.no/skole/api/media/{video_id}',
871 return self
.url_result(f
'nrk:{nrk_id}')