2 from __future__ import unicode_literals
6 from .common import InfoExtractor
7 from ..compat import compat_str
16 class NRKIE(InfoExtractor):
17 _VALID_URL = r'(?:nrk:|http://(?:www\.)?nrk\.no/video/PS\*)(?P<id>\d+)'
21 'url': 'http://www.nrk.no/video/PS*150533',
22 'md5': 'bccd850baebefe23b56d708a113229c2',
26 'title': 'Dompap og andre fugler i Piip-Show',
27 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
32 'url': 'http://www.nrk.no/video/PS*154915',
33 'md5': '0b1493ba1aae7d9579a5ad5531bc395a',
37 'title': 'Slik høres internett ut når du er blind',
38 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
47 data = self._download_json(
48 'http://v8.psapi.nrk.no/mediaelement/%s' % video_id,
49 video_id, 'Downloading media JSON')
51 if data['usageRights']['isGeoBlocked']:
53 'NRK har ikke rettig-heter til å vise dette programmet utenfor Norge',
56 video_url = data['mediaUrl'] + '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81'
58 duration = parse_duration(data.get('duration'))
60 images = data.get('images')
62 thumbnails = images['webImages']
63 thumbnails.sort(key=lambda image: image['pixelWidth'])
64 thumbnail = thumbnails[-1]['imageUrl']
72 'title': data['title'],
73 'description': data['description'],
75 'thumbnail': thumbnail,
79 class NRKPlaylistIE(InfoExtractor):
80 _VALID_URL = r'http://(?:www\.)?nrk\.no/(?!video)(?:[^/]+/)+(?P<id>[^/]+)'
83 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
85 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
86 'title': 'Gjenopplev den historiske solformørkelsen',
87 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
91 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
93 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
94 'title': 'Rivertonprisen til Karin Fossum',
95 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
100 def _real_extract(self, url):
101 playlist_id = self._match_id(url)
103 webpage = self._download_webpage(url, playlist_id)
106 self.url_result('nrk:%s' % video_id, 'NRK')
107 for video_id in re.findall(
108 r'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"',
112 playlist_title = self._og_search_title(webpage)
113 playlist_description = self._og_search_description(webpage)
115 return self.playlist_result(
116 entries, playlist_id, playlist_title, playlist_description)
119 class NRKTVIE(InfoExtractor):
120 _VALID_URL = r'(?P<baseurl>http://tv\.nrk(?:super)?\.no/)(?:serie/[^/]+|program)/(?P<id>[a-zA-Z]{4}\d{8})(?:/\d{2}-\d{2}-\d{4})?(?:#del=(?P<part_id>\d+))?'
124 'url': 'http://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
125 'md5': 'adf2c5454fa2bf032f47a9f8fb351342',
127 'id': 'MUHH48000314',
129 'title': '20 spørsmål',
130 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
131 'upload_date': '20140523',
136 'url': 'http://tv.nrk.no/program/mdfp15000514',
137 'md5': '383650ece2b25ecec996ad7b5bb2a384',
139 'id': 'mdfp15000514',
141 'title': 'Kunnskapskanalen: Grunnlovsjubiléet - Stor ståhei for ingenting',
142 'description': 'md5:654c12511f035aed1e42bdf5db3b206a',
143 'upload_date': '20140524',
148 # single playlist video
149 'url': 'http://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
150 'md5': 'adbd1dbd813edaf532b0a253780719c2',
152 'id': 'MSPO40010515-part2',
154 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
155 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
156 'upload_date': '20150106',
158 'skip': 'Only works from Norway',
161 'url': 'http://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
164 'md5': '9480285eff92d64f06e02a5367970a7a',
166 'id': 'MSPO40010515-part1',
168 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 1:2)',
169 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
170 'upload_date': '20150106',
174 'md5': 'adbd1dbd813edaf532b0a253780719c2',
176 'id': 'MSPO40010515-part2',
178 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
179 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
180 'upload_date': '20150106',
185 'id': 'MSPO40010515',
186 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn',
187 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
188 'upload_date': '20150106',
189 'duration': 6947.5199999999995,
191 'skip': 'Only works from Norway',
195 def _debug_print(self, txt):
196 if self._downloader.params.get('verbose', False):
197 self.to_screen('[debug] %s' % txt)
199 def _get_subtitles(self, subtitlesurl, video_id, baseurl):
200 url = "%s%s" % (baseurl, subtitlesurl)
201 self._debug_print('%s: Subtitle url: %s' % (video_id, url))
202 captions = self._download_xml(
203 url, video_id, 'Downloading subtitles',
204 transform_source=lambda s: s.replace(r'<br />', '\r\n'))
205 lang = captions.get('lang', 'no')
206 ps = captions.findall('./{0}body/{0}div/{0}p'.format('{http://www.w3.org/ns/ttml}'))
208 for pos, p in enumerate(ps):
209 begin = parse_duration(p.get('begin'))
210 duration = parse_duration(p.get('dur'))
211 starttime = self._subtitles_timecode(begin)
212 endtime = self._subtitles_timecode(begin + duration)
213 srt += '%s\r\n%s --> %s\r\n%s\r\n\r\n' % (compat_str(pos), starttime, endtime, p.text)
215 {'ext': 'ttml', 'url': url},
216 {'ext': 'srt', 'data': srt},
219 def _extract_f4m(self, manifest_url, video_id):
220 return self._extract_f4m_formats(manifest_url + '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124', video_id)
222 def _real_extract(self, url):
223 mobj = re.match(self._VALID_URL, url)
224 video_id = mobj.group('id')
225 part_id = mobj.group('part_id')
226 baseurl = mobj.group('baseurl')
228 webpage = self._download_webpage(url, video_id)
230 title = self._html_search_meta(
231 'title', webpage, 'title')
232 description = self._html_search_meta(
233 'description', webpage, 'description')
235 thumbnail = self._html_search_regex(
236 r'data-posterimage="([^"]+)"',
237 webpage, 'thumbnail', fatal=False)
238 upload_date = unified_strdate(self._html_search_meta(
239 'rightsfrom', webpage, 'upload date', fatal=False))
240 duration = float_or_none(self._html_search_regex(
241 r'data-duration="([^"]+)"',
242 webpage, 'duration', fatal=False))
246 r'<a href="#del=(\d+)"[^>]+data-argument="([^"]+)">([^<]+)</a>', webpage)
249 for current_part_id, stream_url, part_title in parts:
250 if part_id and current_part_id != part_id:
252 video_part_id = '%s-part%s' % (video_id, current_part_id)
253 formats = self._extract_f4m(stream_url, video_part_id)
257 'description': description,
258 'thumbnail': thumbnail,
259 'upload_date': upload_date,
266 playlist = self.playlist_result(entries, video_id, title, description)
268 'thumbnail': thumbnail,
269 'upload_date': upload_date,
270 'duration': duration,
276 f4m_url = re.search(r'data-media="([^"]+)"', webpage)
278 formats.extend(self._extract_f4m(f4m_url.group(1), video_id))
280 m3u8_url = re.search(r'data-hls-media="([^"]+)"', webpage)
282 formats.extend(self._extract_m3u8_formats(m3u8_url.group(1), video_id, 'mp4'))
283 self._sort_formats(formats)
285 subtitles_url = self._html_search_regex(
286 r'data-subtitlesurl[ ]*=[ ]*"([^"]+)"',
287 webpage, 'subtitle URL', default=None)
290 subtitles = self.extract_subtitles(subtitles_url, video_id, baseurl)
295 'description': description,
296 'thumbnail': thumbnail,
297 'upload_date': upload_date,
298 'duration': duration,
300 'subtitles': subtitles,