2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
9 compat_urllib_parse_unquote
,
20 class NRKIE(InfoExtractor
):
21 _VALID_URL
= r
'(?:nrk:|https?://(?:www\.)?nrk\.no/video/PS\*)(?P<id>\d+)'
25 'url': 'http://www.nrk.no/video/PS*150533',
26 'md5': 'bccd850baebefe23b56d708a113229c2',
30 'title': 'Dompap og andre fugler i Piip-Show',
31 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
36 'url': 'http://www.nrk.no/video/PS*154915',
37 'md5': '0b1493ba1aae7d9579a5ad5531bc395a',
41 'title': 'Slik høres internett ut når du er blind',
42 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
48 def _real_extract(self
, url
):
49 video_id
= self
._match
_id
(url
)
51 data
= self
._download
_json
(
52 'http://v8.psapi.nrk.no/mediaelement/%s' % video_id
,
53 video_id
, 'Downloading media JSON')
55 media_url
= data
.get('mediaUrl')
58 if data
['usageRights']['isGeoBlocked']:
60 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
63 if determine_ext(media_url
) == 'f4m':
64 formats
= self
._extract
_f
4m
_formats
(
65 media_url
+ '?hdcore=3.5.0&plugin=aasp-3.5.0.151.81', video_id
, f4m_id
='hds')
72 duration
= parse_duration(data
.get('duration'))
74 images
= data
.get('images')
76 thumbnails
= images
['webImages']
77 thumbnails
.sort(key
=lambda image
: image
['pixelWidth'])
78 thumbnail
= thumbnails
[-1]['imageUrl']
84 'title': data
['title'],
85 'description': data
['description'],
87 'thumbnail': thumbnail
,
92 class NRKPlaylistIE(InfoExtractor
):
93 _VALID_URL
= r
'https?://(?:www\.)?nrk\.no/(?!video|skole)(?:[^/]+/)+(?P<id>[^/]+)'
96 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
98 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
99 'title': 'Gjenopplev den historiske solformørkelsen',
100 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
104 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
106 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
107 'title': 'Rivertonprisen til Karin Fossum',
108 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
113 def _real_extract(self
, url
):
114 playlist_id
= self
._match
_id
(url
)
116 webpage
= self
._download
_webpage
(url
, playlist_id
)
119 self
.url_result('nrk:%s' % video_id
, 'NRK')
120 for video_id
in re
.findall(
121 r
'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"',
125 playlist_title
= self
._og
_search
_title
(webpage
)
126 playlist_description
= self
._og
_search
_description
(webpage
)
128 return self
.playlist_result(
129 entries
, playlist_id
, playlist_title
, playlist_description
)
132 class NRKSkoleIE(InfoExtractor
):
133 IE_DESC
= 'NRK Skole'
134 _VALID_URL
= r
'https?://(?:www\.)?nrk\.no/skole/klippdetalj?.*\btopic=(?P<id>[^/?#&]+)'
137 'url': 'http://nrk.no/skole/klippdetalj?topic=nrk:klipp/616532',
138 'md5': '04cd85877cc1913bce73c5d28a47e00f',
142 'title': 'Genetikk og eneggede tvillinger',
143 'description': 'md5:3aca25dcf38ec30f0363428d2b265f8d',
147 'url': 'http://www.nrk.no/skole/klippdetalj?topic=nrk%3Aklipp%2F616532#embed',
148 'only_matching': True,
150 'url': 'http://www.nrk.no/skole/klippdetalj?topic=urn:x-mediadb:21379',
151 'only_matching': True,
154 def _real_extract(self
, url
):
155 video_id
= compat_urllib_parse_unquote(self
._match
_id
(url
))
157 webpage
= self
._download
_webpage
(url
, video_id
)
159 nrk_id
= self
._search
_regex
(r
'data-nrk-id=["\'](\d
+)', webpage, 'nrk
id')
160 return self.url_result('nrk
:%s' % nrk_id)
163 class NRKTVIE(InfoExtractor):
164 IE_DESC = 'NRK TV
and NRK Radio
'
165 _VALID_URL = r'(?P
<baseurl
>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+))?'
169 'url': 'https://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
171 'id': 'MUHH48000314',
173 'title': '20 spørsmål',
174 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
175 'upload_date': '20140523',
180 'skip_download': True,
184 'url': 'https://tv.nrk.no/program/mdfp15000514',
186 'id': 'mdfp15000514',
188 'title': 'Grunnlovsjubiléet - Stor ståhei for ingenting',
189 'description': 'md5:654c12511f035aed1e42bdf5db3b206a',
190 'upload_date': '20140524',
195 'skip_download': True,
199 # single playlist video
200 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
201 'md5': 'adbd1dbd813edaf532b0a253780719c2',
203 'id': 'MSPO40010515-part2',
205 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
206 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
207 'upload_date': '20150106',
209 'skip': 'Only works from Norway',
212 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
215 'md5': '9480285eff92d64f06e02a5367970a7a',
217 'id': 'MSPO40010515-part1',
219 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 1:2)',
220 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
221 'upload_date': '20150106',
225 'md5': 'adbd1dbd813edaf532b0a253780719c2',
227 'id': 'MSPO40010515-part2',
229 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
230 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
231 'upload_date': '20150106',
236 'id': 'MSPO40010515',
237 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn',
238 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
239 'upload_date': '20150106',
240 'duration': 6947.5199999999995,
242 'skip': 'Only works from Norway',
245 'url': 'https://radio.nrk.no/serie/dagsnytt/NPUB21019315/12-07-2015#',
246 'only_matching': True,
250 def _extract_f4m(self
, manifest_url
, video_id
):
251 return self
._extract
_f
4m
_formats
(
252 manifest_url
+ '?hdcore=3.1.1&plugin=aasp-3.1.1.69.124', video_id
, f4m_id
='hds')
254 def _real_extract(self
, url
):
255 mobj
= re
.match(self
._VALID
_URL
, url
)
256 video_id
= mobj
.group('id')
257 part_id
= mobj
.group('part_id')
258 base_url
= mobj
.group('baseurl')
260 webpage
= self
._download
_webpage
(url
, video_id
)
262 title
= self
._html
_search
_meta
(
263 'title', webpage
, 'title')
264 description
= self
._html
_search
_meta
(
265 'description', webpage
, 'description')
267 thumbnail
= self
._html
_search
_regex
(
268 r
'data-posterimage="([^"]+)"',
269 webpage
, 'thumbnail', fatal
=False)
270 upload_date
= unified_strdate(self
._html
_search
_meta
(
271 'rightsfrom', webpage
, 'upload date', fatal
=False))
272 duration
= float_or_none(self
._html
_search
_regex
(
273 r
'data-duration="([^"]+)"',
274 webpage
, 'duration', fatal
=False))
278 r
'<a href="#del=(\d+)"[^>]+data-argument="([^"]+)">([^<]+)</a>', webpage
)
281 for current_part_id
, stream_url
, part_title
in parts
:
282 if part_id
and current_part_id
!= part_id
:
284 video_part_id
= '%s-part%s' % (video_id
, current_part_id
)
285 formats
= self
._extract
_f
4m
(stream_url
, video_part_id
)
289 'description': description
,
290 'thumbnail': thumbnail
,
291 'upload_date': upload_date
,
298 playlist
= self
.playlist_result(entries
, video_id
, title
, description
)
300 'thumbnail': thumbnail
,
301 'upload_date': upload_date
,
302 'duration': duration
,
308 f4m_url
= re
.search(r
'data-media="([^"]+)"', webpage
)
310 formats
.extend(self
._extract
_f
4m
(f4m_url
.group(1), video_id
))
312 m3u8_url
= re
.search(r
'data-hls-media="([^"]+)"', webpage
)
314 formats
.extend(self
._extract
_m
3u8_formats
(m3u8_url
.group(1), video_id
, 'mp4', m3u8_id
='hls'))
315 self
._sort
_formats
(formats
)
317 subtitles_url
= self
._html
_search
_regex
(
318 r
'data-subtitlesurl\s*=\s*(["\'])(?P
<url
>.+?
)\
1',
319 webpage, 'subtitle URL
', default=None, group='url
')
324 'url
': compat_urlparse.urljoin(base_url, subtitles_url),
330 'description
': description,
331 'thumbnail
': thumbnail,
332 'upload_date
': upload_date,
333 'duration
': duration,
335 'subtitles
': subtitles,