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):
18 return self._extract_f4m_formats(
19 manifest_url + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81',
20 video_id, f4m_id='hds', fatal=fatal)
22 def _real_extract(self, url):
23 video_id = self._match_id(url)
25 data = self._download_json(
26 'http://%s/mediaelement/%s' % (self._API_HOST, video_id),
27 video_id, 'Downloading mediaelement JSON')
29 title = data.get('fullTitle') or data.get('mainTitle') or data['title']
30 video_id = data.get('id') or video_id
34 media_assets = data.get('mediaAssets')
35 if media_assets and isinstance(media_assets, list):
36 def video_id_and_title(idx):
37 return ((video_id, title) if len(media_assets) == 1
38 else ('%s-%d' % (video_id, idx), '%s (Part %d)' % (title, idx)))
39 for num, asset in enumerate(media_assets, 1):
40 asset_url = asset.get('url')
43 formats = self._extract_formats(asset_url, video_id, fatal=False)
46 self._sort_formats(formats)
47 entry_id, entry_title = video_id_and_title(num)
48 duration = parse_duration(asset.get('duration'))
50 for subtitle in ('webVtt', 'timedText'):
51 subtitle_url = asset.get('%sSubtitlesUrl' % subtitle)
53 subtitles.setdefault('no', []).append({'url': subtitle_url})
55 'id': asset.get('carrierId') or entry_id,
58 'subtitles': subtitles,
63 media_url = data.get('mediaUrl')
65 formats = self._extract_formats(media_url, video_id)
66 self._sort_formats(formats)
67 duration = parse_duration(data.get('duration'))
76 if data.get('usageRights', {}).get('isGeoBlocked'):
78 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
81 conviva = data.get('convivaStatistics') or {}
82 series = conviva.get('seriesName') or data.get('seriesTitle')
83 episode = conviva.get('episodeName') or data.get('episodeNumberOrDate')
86 images = data.get('images')
87 if images and isinstance(images, dict):
88 web_images = images.get('webImages')
89 if isinstance(web_images, list):
91 'url': image['imageUrl'],
92 'width': int_or_none(image.get('width')),
93 'height': int_or_none(image.get('height')),
94 } for image in web_images if image.get('imageUrl')]
96 description = data.get('description')
99 'description': description,
102 'age_limit': parse_age_limit(data.get('legalAge')),
103 'thumbnails': thumbnails,
106 vcodec = 'none' if data.get('mediaType') == 'Audio' else None
108 # TODO: extract chapters when https://github.com/rg3/youtube-dl/pull/9409 is merged
110 for entry in entries:
111 entry.update(common_info)
112 for f in entry['formats']:
115 return self.playlist_result(entries, video_id, title, description)
118 class NRKIE(NRKBaseIE):
119 _VALID_URL = r'(?:nrk:|https?://(?:www\.)?nrk\.no/video/PS\*)(?P<id>\d+)'
120 _API_HOST = 'v8.psapi.nrk.no'
123 'url': 'http://www.nrk.no/video/PS*150533',
128 'title': 'Dompap og andre fugler i Piip-Show',
129 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
134 'url': 'http://www.nrk.no/video/PS*154915',
139 'title': 'Slik høres internett ut når du er blind',
140 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
146 class NRKTVIE(NRKBaseIE):
147 IE_DESC = 'NRK TV and NRK Radio'
148 _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+))?'
149 _API_HOST = 'psapi-we.nrk.no'
152 'url': 'https://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
154 'id': 'MUHH48000314',
156 'title': '20 spørsmål',
157 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
158 'upload_date': '20140523',
163 'skip_download': True,
166 'url': 'https://tv.nrk.no/program/mdfp15000514',
168 'id': 'mdfp15000514',
170 'title': 'Grunnlovsjubiléet - Stor ståhei for ingenting',
171 'description': 'md5:654c12511f035aed1e42bdf5db3b206a',
172 'upload_date': '20140524',
177 'skip_download': True,
180 # single playlist video
181 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
182 'md5': 'adbd1dbd813edaf532b0a253780719c2',
184 'id': 'MSPO40010515-part2',
186 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
187 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
188 'upload_date': '20150106',
190 'skip': 'Only works from Norway',
192 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
194 'md5': '9480285eff92d64f06e02a5367970a7a',
196 'id': 'MSPO40010515-part1',
198 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 1:2)',
199 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
200 'upload_date': '20150106',
203 'md5': 'adbd1dbd813edaf532b0a253780719c2',
205 'id': 'MSPO40010515-part2',
207 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
208 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
209 'upload_date': '20150106',
213 'id': 'MSPO40010515',
214 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn',
215 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
216 'upload_date': '20150106',
219 'skip': 'Only works from Norway',
221 'url': 'https://radio.nrk.no/serie/dagsnytt/NPUB21019315/12-07-2015#',
222 'only_matching': True,
226 class NRKPlaylistIE(InfoExtractor):
227 _VALID_URL = r'https?://(?:www\.)?nrk\.no/(?!video|skole)(?:[^/]+/)+(?P<id>[^/]+)'
230 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
232 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
233 'title': 'Gjenopplev den historiske solformørkelsen',
234 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
238 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
240 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
241 'title': 'Rivertonprisen til Karin Fossum',
242 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
247 def _real_extract(self, url):
248 playlist_id = self._match_id(url)
250 webpage = self._download_webpage(url, playlist_id)
253 self.url_result('nrk:%s' % video_id, 'NRK')
254 for video_id in re.findall(
255 r'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"',
259 playlist_title = self._og_search_title(webpage)
260 playlist_description = self._og_search_description(webpage)
262 return self.playlist_result(
263 entries, playlist_id, playlist_title, playlist_description)
266 class NRKSkoleIE(InfoExtractor):
267 IE_DESC = 'NRK Skole'
268 _VALID_URL = r'https?://(?:www\.)?nrk\.no/skole/klippdetalj?.*\btopic=(?P<id>[^/?#&]+)'
271 'url': 'http://nrk.no/skole/klippdetalj?topic=nrk:klipp/616532',
272 'md5': '04cd85877cc1913bce73c5d28a47e00f',
276 'title': 'Genetikk og eneggede tvillinger',
277 'description': 'md5:3aca25dcf38ec30f0363428d2b265f8d',
281 'url': 'http://www.nrk.no/skole/klippdetalj?topic=nrk%3Aklipp%2F616532#embed',
282 'only_matching': True,
284 'url': 'http://www.nrk.no/skole/klippdetalj?topic=urn:x-mediadb:21379',
285 'only_matching': True,
288 def _real_extract(self, url):
289 video_id = compat_urllib_parse_unquote(self._match_id(url))
291 webpage = self._download_webpage(url, video_id)
293 nrk_id = self._search_regex(r'data-nrk-id=["\'](\d+)', webpage, 'nrk id')
294 return self.url_result('nrk:%s' % nrk_id)