You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

655 lines
23 KiB

8 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_str,
  7. compat_urllib_parse_unquote,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. int_or_none,
  12. JSON_LD_RE,
  13. NO_DEFAULT,
  14. parse_age_limit,
  15. parse_duration,
  16. try_get,
  17. )
  18. class NRKBaseIE(InfoExtractor):
  19. _GEO_COUNTRIES = ['NO']
  20. _api_host = None
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. api_hosts = (self._api_host, ) if self._api_host else self._API_HOSTS
  24. for api_host in api_hosts:
  25. data = self._download_json(
  26. 'http://%s/mediaelement/%s' % (api_host, video_id),
  27. video_id, 'Downloading mediaelement JSON',
  28. fatal=api_host == api_hosts[-1])
  29. if not data:
  30. continue
  31. self._api_host = api_host
  32. break
  33. title = data.get('fullTitle') or data.get('mainTitle') or data['title']
  34. video_id = data.get('id') or video_id
  35. entries = []
  36. conviva = data.get('convivaStatistics') or {}
  37. live = (data.get('mediaElementType') == 'Live' or
  38. data.get('isLive') is True or conviva.get('isLive'))
  39. def make_title(t):
  40. return self._live_title(t) if live else t
  41. media_assets = data.get('mediaAssets')
  42. if media_assets and isinstance(media_assets, list):
  43. def video_id_and_title(idx):
  44. return ((video_id, title) if len(media_assets) == 1
  45. else ('%s-%d' % (video_id, idx), '%s (Part %d)' % (title, idx)))
  46. for num, asset in enumerate(media_assets, 1):
  47. asset_url = asset.get('url')
  48. if not asset_url:
  49. continue
  50. formats = self._extract_akamai_formats(asset_url, video_id)
  51. if not formats:
  52. continue
  53. self._sort_formats(formats)
  54. # Some f4m streams may not work with hdcore in fragments' URLs
  55. for f in formats:
  56. extra_param = f.get('extra_param_to_segment_url')
  57. if extra_param and 'hdcore' in extra_param:
  58. del f['extra_param_to_segment_url']
  59. entry_id, entry_title = video_id_and_title(num)
  60. duration = parse_duration(asset.get('duration'))
  61. subtitles = {}
  62. for subtitle in ('webVtt', 'timedText'):
  63. subtitle_url = asset.get('%sSubtitlesUrl' % subtitle)
  64. if subtitle_url:
  65. subtitles.setdefault('no', []).append({
  66. 'url': compat_urllib_parse_unquote(subtitle_url)
  67. })
  68. entries.append({
  69. 'id': asset.get('carrierId') or entry_id,
  70. 'title': make_title(entry_title),
  71. 'duration': duration,
  72. 'subtitles': subtitles,
  73. 'formats': formats,
  74. })
  75. if not entries:
  76. media_url = data.get('mediaUrl')
  77. if media_url:
  78. formats = self._extract_akamai_formats(media_url, video_id)
  79. self._sort_formats(formats)
  80. duration = parse_duration(data.get('duration'))
  81. entries = [{
  82. 'id': video_id,
  83. 'title': make_title(title),
  84. 'duration': duration,
  85. 'formats': formats,
  86. }]
  87. if not entries:
  88. MESSAGES = {
  89. 'ProgramRightsAreNotReady': 'Du kan dessverre ikke se eller høre programmet',
  90. 'ProgramRightsHasExpired': 'Programmet har gått ut',
  91. 'ProgramIsGeoBlocked': 'NRK har ikke rettigheter til å vise dette programmet utenfor Norge',
  92. }
  93. message_type = data.get('messageType', '')
  94. # Can be ProgramIsGeoBlocked or ChannelIsGeoBlocked*
  95. if 'IsGeoBlocked' in message_type:
  96. self.raise_geo_restricted(
  97. msg=MESSAGES.get('ProgramIsGeoBlocked'),
  98. countries=self._GEO_COUNTRIES)
  99. raise ExtractorError(
  100. '%s said: %s' % (self.IE_NAME, MESSAGES.get(
  101. message_type, message_type)),
  102. expected=True)
  103. series = conviva.get('seriesName') or data.get('seriesTitle')
  104. episode = conviva.get('episodeName') or data.get('episodeNumberOrDate')
  105. season_number = None
  106. episode_number = None
  107. if data.get('mediaElementType') == 'Episode':
  108. _season_episode = data.get('scoresStatistics', {}).get('springStreamStream') or \
  109. data.get('relativeOriginUrl', '')
  110. EPISODENUM_RE = [
  111. r'/s(?P<season>\d{,2})e(?P<episode>\d{,2})\.',
  112. r'/sesong-(?P<season>\d{,2})/episode-(?P<episode>\d{,2})',
  113. ]
  114. season_number = int_or_none(self._search_regex(
  115. EPISODENUM_RE, _season_episode, 'season number',
  116. default=None, group='season'))
  117. episode_number = int_or_none(self._search_regex(
  118. EPISODENUM_RE, _season_episode, 'episode number',
  119. default=None, group='episode'))
  120. thumbnails = None
  121. images = data.get('images')
  122. if images and isinstance(images, dict):
  123. web_images = images.get('webImages')
  124. if isinstance(web_images, list):
  125. thumbnails = [{
  126. 'url': image['imageUrl'],
  127. 'width': int_or_none(image.get('width')),
  128. 'height': int_or_none(image.get('height')),
  129. } for image in web_images if image.get('imageUrl')]
  130. description = data.get('description')
  131. category = data.get('mediaAnalytics', {}).get('category')
  132. common_info = {
  133. 'description': description,
  134. 'series': series,
  135. 'episode': episode,
  136. 'season_number': season_number,
  137. 'episode_number': episode_number,
  138. 'categories': [category] if category else None,
  139. 'age_limit': parse_age_limit(data.get('legalAge')),
  140. 'thumbnails': thumbnails,
  141. }
  142. vcodec = 'none' if data.get('mediaType') == 'Audio' else None
  143. for entry in entries:
  144. entry.update(common_info)
  145. for f in entry['formats']:
  146. f['vcodec'] = vcodec
  147. points = data.get('shortIndexPoints')
  148. if isinstance(points, list):
  149. chapters = []
  150. for next_num, point in enumerate(points, start=1):
  151. if not isinstance(point, dict):
  152. continue
  153. start_time = parse_duration(point.get('startPoint'))
  154. if start_time is None:
  155. continue
  156. end_time = parse_duration(
  157. data.get('duration')
  158. if next_num == len(points)
  159. else points[next_num].get('startPoint'))
  160. if end_time is None:
  161. continue
  162. chapters.append({
  163. 'start_time': start_time,
  164. 'end_time': end_time,
  165. 'title': point.get('title'),
  166. })
  167. if chapters and len(entries) == 1:
  168. entries[0]['chapters'] = chapters
  169. return self.playlist_result(entries, video_id, title, description)
  170. class NRKIE(NRKBaseIE):
  171. _VALID_URL = r'''(?x)
  172. (?:
  173. nrk:|
  174. https?://
  175. (?:
  176. (?:www\.)?nrk\.no/video/PS\*|
  177. v8[-.]psapi\.nrk\.no/mediaelement/
  178. )
  179. )
  180. (?P<id>[^?#&]+)
  181. '''
  182. _API_HOSTS = ('psapi.nrk.no', 'v8-psapi.nrk.no')
  183. _TESTS = [{
  184. # video
  185. 'url': 'http://www.nrk.no/video/PS*150533',
  186. 'md5': '2f7f6eeb2aacdd99885f355428715cfa',
  187. 'info_dict': {
  188. 'id': '150533',
  189. 'ext': 'mp4',
  190. 'title': 'Dompap og andre fugler i Piip-Show',
  191. 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
  192. 'duration': 263,
  193. }
  194. }, {
  195. # audio
  196. 'url': 'http://www.nrk.no/video/PS*154915',
  197. # MD5 is unstable
  198. 'info_dict': {
  199. 'id': '154915',
  200. 'ext': 'flv',
  201. 'title': 'Slik høres internett ut når du er blind',
  202. 'description': 'md5:a621f5cc1bd75c8d5104cb048c6b8568',
  203. 'duration': 20,
  204. }
  205. }, {
  206. 'url': 'nrk:ecc1b952-96dc-4a98-81b9-5296dc7a98d9',
  207. 'only_matching': True,
  208. }, {
  209. 'url': 'nrk:clip/7707d5a3-ebe7-434a-87d5-a3ebe7a34a70',
  210. 'only_matching': True,
  211. }, {
  212. 'url': 'https://v8-psapi.nrk.no/mediaelement/ecc1b952-96dc-4a98-81b9-5296dc7a98d9',
  213. 'only_matching': True,
  214. }]
  215. class NRKTVIE(NRKBaseIE):
  216. IE_DESC = 'NRK TV and NRK Radio'
  217. _EPISODE_RE = r'(?P<id>[a-zA-Z]{4}\d{8})'
  218. _VALID_URL = r'''(?x)
  219. https?://
  220. (?:tv|radio)\.nrk(?:super)?\.no/
  221. (?:serie/[^/]+|program)/
  222. (?![Ee]pisodes)%s
  223. (?:/\d{2}-\d{2}-\d{4})?
  224. (?:\#del=(?P<part_id>\d+))?
  225. ''' % _EPISODE_RE
  226. _API_HOSTS = ('psapi-ne.nrk.no', 'psapi-we.nrk.no')
  227. _TESTS = [{
  228. 'url': 'https://tv.nrk.no/serie/20-spoersmaal-tv/MUHH48000314/23-05-2014',
  229. 'md5': '4e9ca6629f09e588ed240fb11619922a',
  230. 'info_dict': {
  231. 'id': 'MUHH48000314AA',
  232. 'ext': 'mp4',
  233. 'title': '20 spørsmål 23.05.2014',
  234. 'description': 'md5:bdea103bc35494c143c6a9acdd84887a',
  235. 'duration': 1741,
  236. 'series': '20 spørsmål - TV',
  237. 'episode': '23.05.2014',
  238. },
  239. }, {
  240. 'url': 'https://tv.nrk.no/program/mdfp15000514',
  241. 'info_dict': {
  242. 'id': 'MDFP15000514CA',
  243. 'ext': 'mp4',
  244. 'title': 'Grunnlovsjubiléet - Stor ståhei for ingenting 24.05.2014',
  245. 'description': 'md5:89290c5ccde1b3a24bb8050ab67fe1db',
  246. 'duration': 4605,
  247. 'series': 'Kunnskapskanalen',
  248. 'episode': '24.05.2014',
  249. },
  250. 'params': {
  251. 'skip_download': True,
  252. },
  253. }, {
  254. # single playlist video
  255. 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015#del=2',
  256. 'info_dict': {
  257. 'id': 'MSPO40010515-part2',
  258. 'ext': 'flv',
  259. 'title': 'Tour de Ski: Sprint fri teknikk, kvinner og menn 06.01.2015 (del 2:2)',
  260. 'description': 'md5:238b67b97a4ac7d7b4bf0edf8cc57d26',
  261. },
  262. 'params': {
  263. 'skip_download': True,
  264. },
  265. 'expected_warnings': ['Video is geo restricted'],
  266. 'skip': 'particular part is not supported currently',
  267. }, {
  268. 'url': 'https://tv.nrk.no/serie/tour-de-ski/MSPO40010515/06-01-2015',
  269. 'playlist': [{
  270. 'info_dict': {
  271. 'id': 'MSPO40010515AH',
  272. 'ext': 'mp4',
  273. 'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015 (Part 1)',
  274. 'description': 'md5:c03aba1e917561eface5214020551b7a',
  275. 'duration': 772,
  276. 'series': 'Tour de Ski',
  277. 'episode': '06.01.2015',
  278. },
  279. 'params': {
  280. 'skip_download': True,
  281. },
  282. }, {
  283. 'info_dict': {
  284. 'id': 'MSPO40010515BH',
  285. 'ext': 'mp4',
  286. 'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015 (Part 2)',
  287. 'description': 'md5:c03aba1e917561eface5214020551b7a',
  288. 'duration': 6175,
  289. 'series': 'Tour de Ski',
  290. 'episode': '06.01.2015',
  291. },
  292. 'params': {
  293. 'skip_download': True,
  294. },
  295. }],
  296. 'info_dict': {
  297. 'id': 'MSPO40010515',
  298. 'title': 'Sprint fri teknikk, kvinner og menn 06.01.2015',
  299. 'description': 'md5:c03aba1e917561eface5214020551b7a',
  300. },
  301. 'expected_warnings': ['Video is geo restricted'],
  302. }, {
  303. 'url': 'https://tv.nrk.no/serie/anno/KMTE50001317/sesong-3/episode-13',
  304. 'info_dict': {
  305. 'id': 'KMTE50001317AA',
  306. 'ext': 'mp4',
  307. 'title': 'Anno 13:30',
  308. 'description': 'md5:11d9613661a8dbe6f9bef54e3a4cbbfa',
  309. 'duration': 2340,
  310. 'series': 'Anno',
  311. 'episode': '13:30',
  312. 'season_number': 3,
  313. 'episode_number': 13,
  314. },
  315. 'params': {
  316. 'skip_download': True,
  317. },
  318. }, {
  319. 'url': 'https://tv.nrk.no/serie/nytt-paa-nytt/MUHH46000317/27-01-2017',
  320. 'info_dict': {
  321. 'id': 'MUHH46000317AA',
  322. 'ext': 'mp4',
  323. 'title': 'Nytt på Nytt 27.01.2017',
  324. 'description': 'md5:5358d6388fba0ea6f0b6d11c48b9eb4b',
  325. 'duration': 1796,
  326. 'series': 'Nytt på nytt',
  327. 'episode': '27.01.2017',
  328. },
  329. 'params': {
  330. 'skip_download': True,
  331. },
  332. }, {
  333. 'url': 'https://radio.nrk.no/serie/dagsnytt/NPUB21019315/12-07-2015#',
  334. 'only_matching': True,
  335. }]
  336. class NRKTVEpisodeIE(InfoExtractor):
  337. _VALID_URL = r'https?://tv\.nrk\.no/serie/(?P<id>[^/]+/sesong/\d+/episode/\d+)'
  338. _TEST = {
  339. 'url': 'https://tv.nrk.no/serie/backstage/sesong/1/episode/8',
  340. 'info_dict': {
  341. 'id': 'MSUI14000816AA',
  342. 'ext': 'mp4',
  343. 'title': 'Backstage 8:30',
  344. 'description': 'md5:de6ca5d5a2d56849e4021f2bf2850df4',
  345. 'duration': 1320,
  346. 'series': 'Backstage',
  347. 'season_number': 1,
  348. 'episode_number': 8,
  349. 'episode': '8:30',
  350. },
  351. 'params': {
  352. 'skip_download': True,
  353. },
  354. }
  355. def _real_extract(self, url):
  356. display_id = self._match_id(url)
  357. webpage = self._download_webpage(url, display_id)
  358. nrk_id = self._parse_json(
  359. self._search_regex(JSON_LD_RE, webpage, 'JSON-LD', group='json_ld'),
  360. display_id)['@id']
  361. assert re.match(NRKTVIE._EPISODE_RE, nrk_id)
  362. return self.url_result(
  363. 'nrk:%s' % nrk_id, ie=NRKIE.ie_key(), video_id=nrk_id)
  364. class NRKTVSerieBaseIE(InfoExtractor):
  365. def _extract_series(self, webpage, display_id, fatal=True):
  366. config = self._parse_json(
  367. self._search_regex(
  368. r'({.+?})\s*,\s*"[^"]+"\s*\)\s*</script>', webpage, 'config',
  369. default='{}' if not fatal else NO_DEFAULT),
  370. display_id, fatal=False)
  371. if not config:
  372. return
  373. return try_get(config, lambda x: x['series'], dict)
  374. def _extract_episodes(self, season):
  375. entries = []
  376. if not isinstance(season, dict):
  377. return entries
  378. episodes = season.get('episodes')
  379. if not isinstance(episodes, list):
  380. return entries
  381. for episode in episodes:
  382. nrk_id = episode.get('prfId')
  383. if not nrk_id or not isinstance(nrk_id, compat_str):
  384. continue
  385. entries.append(self.url_result(
  386. 'nrk:%s' % nrk_id, ie=NRKIE.ie_key(), video_id=nrk_id))
  387. return entries
  388. class NRKTVSeasonIE(NRKTVSerieBaseIE):
  389. _VALID_URL = r'https?://tv\.nrk\.no/serie/[^/]+/sesong/(?P<id>\d+)'
  390. _TEST = {
  391. 'url': 'https://tv.nrk.no/serie/backstage/sesong/1',
  392. 'info_dict': {
  393. 'id': '1',
  394. 'title': 'Sesong 1',
  395. },
  396. 'playlist_mincount': 30,
  397. }
  398. @classmethod
  399. def suitable(cls, url):
  400. return (False if NRKTVIE.suitable(url) or NRKTVEpisodeIE.suitable(url)
  401. else super(NRKTVSeasonIE, cls).suitable(url))
  402. def _real_extract(self, url):
  403. display_id = self._match_id(url)
  404. webpage = self._download_webpage(url, display_id)
  405. series = self._extract_series(webpage, display_id)
  406. season = next(
  407. s for s in series['seasons']
  408. if int(display_id) == s.get('seasonNumber'))
  409. title = try_get(season, lambda x: x['titles']['title'], compat_str)
  410. return self.playlist_result(
  411. self._extract_episodes(season), display_id, title)
  412. class NRKTVSeriesIE(NRKTVSerieBaseIE):
  413. _VALID_URL = r'https?://(?:tv|radio)\.nrk(?:super)?\.no/serie/(?P<id>[^/]+)'
  414. _ITEM_RE = r'(?:data-season=["\']|id=["\']season-)(?P<id>\d+)'
  415. _TESTS = [{
  416. # new layout
  417. 'url': 'https://tv.nrk.no/serie/backstage',
  418. 'info_dict': {
  419. 'id': 'backstage',
  420. 'title': 'Backstage',
  421. 'description': 'md5:c3ec3a35736fca0f9e1207b5511143d3',
  422. },
  423. 'playlist_mincount': 60,
  424. }, {
  425. # old layout
  426. 'url': 'https://tv.nrk.no/serie/groenn-glede',
  427. 'info_dict': {
  428. 'id': 'groenn-glede',
  429. 'title': 'Grønn glede',
  430. 'description': 'md5:7576e92ae7f65da6993cf90ee29e4608',
  431. },
  432. 'playlist_mincount': 9,
  433. }, {
  434. 'url': 'http://tv.nrksuper.no/serie/labyrint',
  435. 'info_dict': {
  436. 'id': 'labyrint',
  437. 'title': 'Labyrint',
  438. 'description': 'md5:58afd450974c89e27d5a19212eee7115',
  439. },
  440. 'playlist_mincount': 3,
  441. }, {
  442. 'url': 'https://tv.nrk.no/serie/broedrene-dal-og-spektralsteinene',
  443. 'only_matching': True,
  444. }, {
  445. 'url': 'https://tv.nrk.no/serie/saving-the-human-race',
  446. 'only_matching': True,
  447. }, {
  448. 'url': 'https://tv.nrk.no/serie/postmann-pat',
  449. 'only_matching': True,
  450. }]
  451. @classmethod
  452. def suitable(cls, url):
  453. return (
  454. False if any(ie.suitable(url)
  455. for ie in (NRKTVIE, NRKTVEpisodeIE, NRKTVSeasonIE))
  456. else super(NRKTVSeriesIE, cls).suitable(url))
  457. def _real_extract(self, url):
  458. series_id = self._match_id(url)
  459. webpage = self._download_webpage(url, series_id)
  460. # New layout (e.g. https://tv.nrk.no/serie/backstage)
  461. series = self._extract_series(webpage, series_id, fatal=False)
  462. if series:
  463. title = try_get(series, lambda x: x['titles']['title'], compat_str)
  464. description = try_get(
  465. series, lambda x: x['titles']['subtitle'], compat_str)
  466. entries = []
  467. for season in series['seasons']:
  468. entries.extend(self._extract_episodes(season))
  469. return self.playlist_result(entries, series_id, title, description)
  470. # Old layout (e.g. https://tv.nrk.no/serie/groenn-glede)
  471. entries = [
  472. self.url_result(
  473. 'https://tv.nrk.no/program/Episodes/{series}/{season}'.format(
  474. series=series_id, season=season_id))
  475. for season_id in re.findall(self._ITEM_RE, webpage)
  476. ]
  477. title = self._html_search_meta(
  478. 'seriestitle', webpage,
  479. 'title', default=None) or self._og_search_title(
  480. webpage, fatal=False)
  481. description = self._html_search_meta(
  482. 'series_description', webpage,
  483. 'description', default=None) or self._og_search_description(webpage)
  484. return self.playlist_result(entries, series_id, title, description)
  485. class NRKTVDirekteIE(NRKTVIE):
  486. IE_DESC = 'NRK TV Direkte and NRK Radio Direkte'
  487. _VALID_URL = r'https?://(?:tv|radio)\.nrk\.no/direkte/(?P<id>[^/?#&]+)'
  488. _TESTS = [{
  489. 'url': 'https://tv.nrk.no/direkte/nrk1',
  490. 'only_matching': True,
  491. }, {
  492. 'url': 'https://radio.nrk.no/direkte/p1_oslo_akershus',
  493. 'only_matching': True,
  494. }]
  495. class NRKPlaylistBaseIE(InfoExtractor):
  496. def _extract_description(self, webpage):
  497. pass
  498. def _real_extract(self, url):
  499. playlist_id = self._match_id(url)
  500. webpage = self._download_webpage(url, playlist_id)
  501. entries = [
  502. self.url_result('nrk:%s' % video_id, NRKIE.ie_key())
  503. for video_id in re.findall(self._ITEM_RE, webpage)
  504. ]
  505. playlist_title = self. _extract_title(webpage)
  506. playlist_description = self._extract_description(webpage)
  507. return self.playlist_result(
  508. entries, playlist_id, playlist_title, playlist_description)
  509. class NRKPlaylistIE(NRKPlaylistBaseIE):
  510. _VALID_URL = r'https?://(?:www\.)?nrk\.no/(?!video|skole)(?:[^/]+/)+(?P<id>[^/]+)'
  511. _ITEM_RE = r'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"'
  512. _TESTS = [{
  513. 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
  514. 'info_dict': {
  515. 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
  516. 'title': 'Gjenopplev den historiske solformørkelsen',
  517. 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
  518. },
  519. 'playlist_count': 2,
  520. }, {
  521. 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
  522. 'info_dict': {
  523. 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
  524. 'title': 'Rivertonprisen til Karin Fossum',
  525. 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
  526. },
  527. 'playlist_count': 5,
  528. }]
  529. def _extract_title(self, webpage):
  530. return self._og_search_title(webpage, fatal=False)
  531. def _extract_description(self, webpage):
  532. return self._og_search_description(webpage)
  533. class NRKTVEpisodesIE(NRKPlaylistBaseIE):
  534. _VALID_URL = r'https?://tv\.nrk\.no/program/[Ee]pisodes/[^/]+/(?P<id>\d+)'
  535. _ITEM_RE = r'data-episode=["\']%s' % NRKTVIE._EPISODE_RE
  536. _TESTS = [{
  537. 'url': 'https://tv.nrk.no/program/episodes/nytt-paa-nytt/69031',
  538. 'info_dict': {
  539. 'id': '69031',
  540. 'title': 'Nytt på nytt, sesong: 201210',
  541. },
  542. 'playlist_count': 4,
  543. }]
  544. def _extract_title(self, webpage):
  545. return self._html_search_regex(
  546. r'<h1>([^<]+)</h1>', webpage, 'title', fatal=False)
  547. class NRKSkoleIE(InfoExtractor):
  548. IE_DESC = 'NRK Skole'
  549. _VALID_URL = r'https?://(?:www\.)?nrk\.no/skole/?\?.*\bmediaId=(?P<id>\d+)'
  550. _TESTS = [{
  551. 'url': 'https://www.nrk.no/skole/?page=search&q=&mediaId=14099',
  552. 'md5': '6bc936b01f9dd8ed45bc58b252b2d9b6',
  553. 'info_dict': {
  554. 'id': '6021',
  555. 'ext': 'mp4',
  556. 'title': 'Genetikk og eneggede tvillinger',
  557. 'description': 'md5:3aca25dcf38ec30f0363428d2b265f8d',
  558. 'duration': 399,
  559. },
  560. }, {
  561. 'url': 'https://www.nrk.no/skole/?page=objectives&subject=naturfag&objective=K15114&mediaId=19355',
  562. 'only_matching': True,
  563. }]
  564. def _real_extract(self, url):
  565. video_id = self._match_id(url)
  566. webpage = self._download_webpage(
  567. 'https://mimir.nrk.no/plugin/1.0/static?mediaId=%s' % video_id,
  568. video_id)
  569. nrk_id = self._parse_json(
  570. self._search_regex(
  571. r'<script[^>]+type=["\']application/json["\'][^>]*>({.+?})</script>',
  572. webpage, 'application json'),
  573. video_id)['activeMedia']['psId']
  574. return self.url_result('nrk:%s' % nrk_id)