2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_parse_unquote
16 class NRKBaseIE(InfoExtractor):
17 def _extract_formats(self, manifest_url, video_id, fatal=True):
19 formats.extend(self._extract_f4m_formats(
20 manifest_url + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81',
21 video_id, f4m_id='hds', fatal=fatal))
22 formats.extend(self._extract_m3u8_formats(manifest_url.replace(
23 'akamaihd.net/z/', 'akamaihd.net/i/').replace('/manifest.f4m', '/master.m3u8'),
24 video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=fatal))
27 def _real_extract(self, url):
28 video_id = self._match_id(url)
30 data = self._download_json(
31 'http://%s/mediaelement/%s' % (self._API_HOST, video_id),
32 video_id, 'Downloading mediaelement JSON')
34 title = data.get('fullTitle') or data.get('mainTitle') or data['title']
35 video_id = data.get('id') or video_id
39 media_assets = data.get('mediaAssets')
40 if media_assets and isinstance(media_assets, list):
41 def video_id_and_title(idx):
42 return ((video_id, title) if len(media_assets) == 1
43 else ('%s-%d' % (video_id, idx), '%s (Part %d)' % (title, idx)))
44 for num, asset in enumerate(media_assets, 1):
45 asset_url = asset.get('url')
48 formats = self._extract_formats(asset_url, video_id, fatal=False)
51 self._sort_formats(formats)
52 entry_id, entry_title = video_id_and_title(num)
53 duration = parse_duration(asset.get('duration'))
55 for subtitle in ('webVtt', 'timedText'):
56 subtitle_url = asset.get('%sSubtitlesUrl' % subtitle)
58 subtitles.setdefault('no', []).append({'url': subtitle_url})
60 'id': asset.get('carrierId') or entry_id,
63 'subtitles': subtitles,
68 media_url = data.get('mediaUrl')
70 formats = self._extract_formats(media_url, video_id)
71 self._sort_formats(formats)
72 duration = parse_duration(data.get('duration'))
81 if data.get('usageRights', {}).get('isGeoBlocked'):
83 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
86 conviva = data.get('convivaStatistics') or {}
87 series = conviva.get('seriesName') or data.get('seriesTitle')
88 episode = conviva.get('episodeName') or data.get('episodeNumberOrDate')
91 images = data.get('images')
92 if images and isinstance(images, dict):
93 web_images = images.get('webImages')
94 if isinstance(web_images, list):
96 'url': image['imageUrl'],
97 'width': int_or_none(image.get('width')),
98 'height': int_or_none(image.get('height')),
99 } for image in web_images if image.get('imageUrl')]
101 description = data.get('description')
104 'description': description,
107 'age_limit': parse_age_limit(data.get('legalAge')),
108 'thumbnails': thumbnails,
111 vcodec = 'none' if data.get('mediaType') == 'Audio' else None
113 # TODO: extract chapters when https://github.com/rg3/youtube-dl/pull/9409 is merged
115 for entry in entries:
116 entry.update(common_info)
117 for f in entry['formats']:
120 return self.playlist_result(entries, video_id, title, description)
123 class NRKIE(NRKBaseIE):
124 _VALID_URL = r'(?:nrk:|https?://(?:www\.)?nrk\.no/video/PS\*)(?P<id>\d+)'
125 _API_HOST = 'v8.psapi.nrk.no'
128 'url': 'http://www.nrk.no/video/PS*150533',
129 'md5': '2f7f6eeb2aacdd99885f355428715cfa',
133 'title': 'Dompap og andre fugler i Piip-Show',
134 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
139 'url': 'http://www.nrk.no/video/PS*154915',
144 'title': 'Slik høres internett ut når du er blind',
145 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
151 class NRKTVIE(NRKBaseIE):
152 IE_DESC = 'NRK TV and NRK Radio'
153 _VALID_URL = r'https?://(?:tv|radio)\.nrk(?:super)?\.no/(?:serie/[^/]+|program)/(?P<id>[a-zA-Z]{4}\d{8})(?:/\d{2}-\d{2}-\d{4})?(?:#del=(?P<part_id>\d+))?'
154 _API_HOST = 'psapi-we.nrk.no'
157 'url': 'https://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
158 'md5': '4e9ca6629f09e588ed240fb11619922a',
160 'id': 'MUHH48000314AA',
162 'title': '20 spørsmål 23.05.2014',
163 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
167 'url': 'https://tv.nrk.no/program/mdfp15000514',
168 'md5': '43d0be26663d380603a9cf0c24366531',
170 'id': 'MDFP15000514CA',
172 'title': 'Grunnlovsjubiléet - Stor ståhei for ingenting 24.05.2014',
173 'description': 'md5:89290c5ccde1b3a24bb8050ab67fe1db',
177 # single playlist video
178 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
179 'md5': 'adbd1dbd813edaf532b0a253780719c2',
181 'id': 'MSPO40010515-part2',
183 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
184 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
186 'skip': 'Only works from Norway',
188 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
190 'md5': '9480285eff92d64f06e02a5367970a7a',
192 'id': 'MSPO40010515-part1',
194 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 1:2)',
195 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
198 'md5': 'adbd1dbd813edaf532b0a253780719c2',
200 'id': 'MSPO40010515-part2',
202 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
203 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
207 'id': 'MSPO40010515',
208 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn',
209 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
212 'skip': 'Only works from Norway',
214 'url': 'https://radio.nrk.no/serie/dagsnytt/NPUB21019315/12-07-2015#',
215 'only_matching': True,
219 class NRKPlaylistIE(InfoExtractor):
220 _VALID_URL = r'https?://(?:www\.)?nrk\.no/(?!video|skole)(?:[^/]+/)+(?P<id>[^/]+)'
223 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
225 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
226 'title': 'Gjenopplev den historiske solformørkelsen',
227 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
231 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
233 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
234 'title': 'Rivertonprisen til Karin Fossum',
235 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
240 def _real_extract(self, url):
241 playlist_id = self._match_id(url)
243 webpage = self._download_webpage(url, playlist_id)
246 self.url_result('nrk:%s' % video_id, 'NRK')
247 for video_id in re.findall(
248 r'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"',
252 playlist_title = self._og_search_title(webpage)
253 playlist_description = self._og_search_description(webpage)
255 return self.playlist_result(
256 entries, playlist_id, playlist_title, playlist_description)
259 class NRKSkoleIE(InfoExtractor):
260 IE_DESC = 'NRK Skole'
261 _VALID_URL = r'https?://(?:www\.)?nrk\.no/skole/klippdetalj?.*\btopic=(?P<id>[^/?#&]+)'
264 'url': 'http://nrk.no/skole/klippdetalj?topic=nrk:klipp/616532',
265 'md5': '04cd85877cc1913bce73c5d28a47e00f',
269 'title': 'Genetikk og eneggede tvillinger',
270 'description': 'md5:3aca25dcf38ec30f0363428d2b265f8d',
274 'url': 'http://www.nrk.no/skole/klippdetalj?topic=nrk%3Aklipp%2F616532#embed',
275 'only_matching': True,
277 'url': 'http://www.nrk.no/skole/klippdetalj?topic=urn:x-mediadb:21379',
278 'only_matching': True,
281 def _real_extract(self, url):
282 video_id = compat_urllib_parse_unquote(self._match_id(url))
284 webpage = self._download_webpage(url, video_id)
286 nrk_id = self._search_regex(r'data-nrk-id=["\'](\d+)', webpage, 'nrk id')
287 return self.url_result('nrk:%s' % nrk_id)