Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

678 строки
24KB

  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'
  38. or 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': '706f34cdf1322577589e369e522b50ef',
  187. 'info_dict': {
  188. 'id': '150533',
  189. 'ext': 'mp4',
  190. 'title': 'Dompap og andre fugler i Piip-Show',
  191. 'description': 'md5:d9261ba34c43b61c812cb6b0269a5c8f',
  192. 'duration': 262,
  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(?:/[^/]+){1,2}|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': '9a167e54d04671eb6317a37b7bc8a280',
  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',
  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:1f97a41f05a9486ee00c56f35f82993d',
  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:1f97a41f05a9486ee00c56f35f82993d',
  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:1f97a41f05a9486ee00c56f35f82993d',
  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. 'url': 'https://tv.nrk.no/serie/lindmo/2018/MUHU11006318/avspiller',
  337. 'only_matching': True,
  338. }]
  339. class NRKTVEpisodeIE(InfoExtractor):
  340. _VALID_URL = r'https?://tv\.nrk\.no/serie/(?P<id>[^/]+/sesong/\d+/episode/\d+)'
  341. _TEST = {
  342. 'url': 'https://tv.nrk.no/serie/backstage/sesong/1/episode/8',
  343. 'info_dict': {
  344. 'id': 'MSUI14000816AA',
  345. 'ext': 'mp4',
  346. 'title': 'Backstage 8:30',
  347. 'description': 'md5:de6ca5d5a2d56849e4021f2bf2850df4',
  348. 'duration': 1320,
  349. 'series': 'Backstage',
  350. 'season_number': 1,
  351. 'episode_number': 8,
  352. 'episode': '8:30',
  353. },
  354. 'params': {
  355. 'skip_download': True,
  356. },
  357. }
  358. def _real_extract(self, url):
  359. display_id = self._match_id(url)
  360. webpage = self._download_webpage(url, display_id)
  361. nrk_id = self._parse_json(
  362. self._search_regex(JSON_LD_RE, webpage, 'JSON-LD', group='json_ld'),
  363. display_id)['@id']
  364. assert re.match(NRKTVIE._EPISODE_RE, nrk_id)
  365. return self.url_result(
  366. 'nrk:%s' % nrk_id, ie=NRKIE.ie_key(), video_id=nrk_id)
  367. class NRKTVSerieBaseIE(InfoExtractor):
  368. def _extract_series(self, webpage, display_id, fatal=True):
  369. config = self._parse_json(
  370. self._search_regex(
  371. (r'INITIAL_DATA_*\s*=\s*({.+?})\s*;',
  372. r'({.+?})\s*,\s*"[^"]+"\s*\)\s*</script>'),
  373. webpage, 'config', default='{}' if not fatal else NO_DEFAULT),
  374. display_id, fatal=False)
  375. if not config:
  376. return
  377. return try_get(
  378. config,
  379. (lambda x: x['initialState']['series'], lambda x: x['series']),
  380. dict)
  381. def _extract_seasons(self, seasons):
  382. if not isinstance(seasons, list):
  383. return []
  384. entries = []
  385. for season in seasons:
  386. entries.extend(self._extract_episodes(season))
  387. return entries
  388. def _extract_episodes(self, season):
  389. if not isinstance(season, dict):
  390. return []
  391. return self._extract_entries(season.get('episodes'))
  392. def _extract_entries(self, entry_list):
  393. if not isinstance(entry_list, list):
  394. return []
  395. entries = []
  396. for episode in entry_list:
  397. nrk_id = episode.get('prfId')
  398. if not nrk_id or not isinstance(nrk_id, compat_str):
  399. continue
  400. entries.append(self.url_result(
  401. 'nrk:%s' % nrk_id, ie=NRKIE.ie_key(), video_id=nrk_id))
  402. return entries
  403. class NRKTVSeasonIE(NRKTVSerieBaseIE):
  404. _VALID_URL = r'https?://tv\.nrk\.no/serie/[^/]+/sesong/(?P<id>\d+)'
  405. _TEST = {
  406. 'url': 'https://tv.nrk.no/serie/backstage/sesong/1',
  407. 'info_dict': {
  408. 'id': '1',
  409. 'title': 'Sesong 1',
  410. },
  411. 'playlist_mincount': 30,
  412. }
  413. @classmethod
  414. def suitable(cls, url):
  415. return (False if NRKTVIE.suitable(url) or NRKTVEpisodeIE.suitable(url)
  416. else super(NRKTVSeasonIE, cls).suitable(url))
  417. def _real_extract(self, url):
  418. display_id = self._match_id(url)
  419. webpage = self._download_webpage(url, display_id)
  420. series = self._extract_series(webpage, display_id)
  421. season = next(
  422. s for s in series['seasons']
  423. if int(display_id) == s.get('seasonNumber'))
  424. title = try_get(season, lambda x: x['titles']['title'], compat_str)
  425. return self.playlist_result(
  426. self._extract_episodes(season), display_id, title)
  427. class NRKTVSeriesIE(NRKTVSerieBaseIE):
  428. _VALID_URL = r'https?://(?:tv|radio)\.nrk(?:super)?\.no/serie/(?P<id>[^/]+)'
  429. _ITEM_RE = r'(?:data-season=["\']|id=["\']season-)(?P<id>\d+)'
  430. _TESTS = [{
  431. # new layout, seasons
  432. 'url': 'https://tv.nrk.no/serie/backstage',
  433. 'info_dict': {
  434. 'id': 'backstage',
  435. 'title': 'Backstage',
  436. 'description': 'md5:c3ec3a35736fca0f9e1207b5511143d3',
  437. },
  438. 'playlist_mincount': 60,
  439. }, {
  440. # new layout, instalments
  441. 'url': 'https://tv.nrk.no/serie/groenn-glede',
  442. 'info_dict': {
  443. 'id': 'groenn-glede',
  444. 'title': 'Grønn glede',
  445. 'description': 'md5:7576e92ae7f65da6993cf90ee29e4608',
  446. },
  447. 'playlist_mincount': 10,
  448. }, {
  449. # old layout
  450. 'url': 'https://tv.nrksuper.no/serie/labyrint',
  451. 'info_dict': {
  452. 'id': 'labyrint',
  453. 'title': 'Labyrint',
  454. 'description': 'md5:318b597330fdac5959247c9b69fdb1ec',
  455. },
  456. 'playlist_mincount': 3,
  457. }, {
  458. 'url': 'https://tv.nrk.no/serie/broedrene-dal-og-spektralsteinene',
  459. 'only_matching': True,
  460. }, {
  461. 'url': 'https://tv.nrk.no/serie/saving-the-human-race',
  462. 'only_matching': True,
  463. }, {
  464. 'url': 'https://tv.nrk.no/serie/postmann-pat',
  465. 'only_matching': True,
  466. }]
  467. @classmethod
  468. def suitable(cls, url):
  469. return (
  470. False if any(ie.suitable(url)
  471. for ie in (NRKTVIE, NRKTVEpisodeIE, NRKTVSeasonIE))
  472. else super(NRKTVSeriesIE, cls).suitable(url))
  473. def _real_extract(self, url):
  474. series_id = self._match_id(url)
  475. webpage = self._download_webpage(url, series_id)
  476. # New layout (e.g. https://tv.nrk.no/serie/backstage)
  477. series = self._extract_series(webpage, series_id, fatal=False)
  478. if series:
  479. title = try_get(series, lambda x: x['titles']['title'], compat_str)
  480. description = try_get(
  481. series, lambda x: x['titles']['subtitle'], compat_str)
  482. entries = []
  483. entries.extend(self._extract_seasons(series.get('seasons')))
  484. entries.extend(self._extract_entries(series.get('instalments')))
  485. entries.extend(self._extract_episodes(series.get('extraMaterial')))
  486. return self.playlist_result(entries, series_id, title, description)
  487. # Old layout (e.g. https://tv.nrksuper.no/serie/labyrint)
  488. entries = [
  489. self.url_result(
  490. 'https://tv.nrk.no/program/Episodes/{series}/{season}'.format(
  491. series=series_id, season=season_id))
  492. for season_id in re.findall(self._ITEM_RE, webpage)
  493. ]
  494. title = self._html_search_meta(
  495. 'seriestitle', webpage,
  496. 'title', default=None) or self._og_search_title(
  497. webpage, fatal=False)
  498. if title:
  499. title = self._search_regex(
  500. r'NRK (?:Super )?TV\s*[-–]\s*(.+)', title, 'title', default=title)
  501. description = self._html_search_meta(
  502. 'series_description', webpage,
  503. 'description', default=None) or self._og_search_description(webpage)
  504. return self.playlist_result(entries, series_id, title, description)
  505. class NRKTVDirekteIE(NRKTVIE):
  506. IE_DESC = 'NRK TV Direkte and NRK Radio Direkte'
  507. _VALID_URL = r'https?://(?:tv|radio)\.nrk\.no/direkte/(?P<id>[^/?#&]+)'
  508. _TESTS = [{
  509. 'url': 'https://tv.nrk.no/direkte/nrk1',
  510. 'only_matching': True,
  511. }, {
  512. 'url': 'https://radio.nrk.no/direkte/p1_oslo_akershus',
  513. 'only_matching': True,
  514. }]
  515. class NRKPlaylistBaseIE(InfoExtractor):
  516. def _extract_description(self, webpage):
  517. pass
  518. def _real_extract(self, url):
  519. playlist_id = self._match_id(url)
  520. webpage = self._download_webpage(url, playlist_id)
  521. entries = [
  522. self.url_result('nrk:%s' % video_id, NRKIE.ie_key())
  523. for video_id in re.findall(self._ITEM_RE, webpage)
  524. ]
  525. playlist_title = self. _extract_title(webpage)
  526. playlist_description = self._extract_description(webpage)
  527. return self.playlist_result(
  528. entries, playlist_id, playlist_title, playlist_description)
  529. class NRKPlaylistIE(NRKPlaylistBaseIE):
  530. _VALID_URL = r'https?://(?:www\.)?nrk\.no/(?!video|skole)(?:[^/]+/)+(?P<id>[^/]+)'
  531. _ITEM_RE = r'class="[^"]*\brich\b[^"]*"[^>]+data-video-id="([^"]+)"'
  532. _TESTS = [{
  533. 'url': 'http://www.nrk.no/troms/gjenopplev-den-historiske-solformorkelsen-1.12270763',
  534. 'info_dict': {
  535. 'id': 'gjenopplev-den-historiske-solformorkelsen-1.12270763',
  536. 'title': 'Gjenopplev den historiske solformørkelsen',
  537. 'description': 'md5:c2df8ea3bac5654a26fc2834a542feed',
  538. },
  539. 'playlist_count': 2,
  540. }, {
  541. 'url': 'http://www.nrk.no/kultur/bok/rivertonprisen-til-karin-fossum-1.12266449',
  542. 'info_dict': {
  543. 'id': 'rivertonprisen-til-karin-fossum-1.12266449',
  544. 'title': 'Rivertonprisen til Karin Fossum',
  545. 'description': 'Første kvinne på 15 år til å vinne krimlitteraturprisen.',
  546. },
  547. 'playlist_count': 2,
  548. }]
  549. def _extract_title(self, webpage):
  550. return self._og_search_title(webpage, fatal=False)
  551. def _extract_description(self, webpage):
  552. return self._og_search_description(webpage)
  553. class NRKTVEpisodesIE(NRKPlaylistBaseIE):
  554. _VALID_URL = r'https?://tv\.nrk\.no/program/[Ee]pisodes/[^/]+/(?P<id>\d+)'
  555. _ITEM_RE = r'data-episode=["\']%s' % NRKTVIE._EPISODE_RE
  556. _TESTS = [{
  557. 'url': 'https://tv.nrk.no/program/episodes/nytt-paa-nytt/69031',
  558. 'info_dict': {
  559. 'id': '69031',
  560. 'title': 'Nytt på nytt, sesong: 201210',
  561. },
  562. 'playlist_count': 4,
  563. }]
  564. def _extract_title(self, webpage):
  565. return self._html_search_regex(
  566. r'<h1>([^<]+)</h1>', webpage, 'title', fatal=False)
  567. class NRKSkoleIE(InfoExtractor):
  568. IE_DESC = 'NRK Skole'
  569. _VALID_URL = r'https?://(?:www\.)?nrk\.no/skole/?\?.*\bmediaId=(?P<id>\d+)'
  570. _TESTS = [{
  571. 'url': 'https://www.nrk.no/skole/?page=search&q=&mediaId=14099',
  572. 'md5': '6bc936b01f9dd8ed45bc58b252b2d9b6',
  573. 'info_dict': {
  574. 'id': '6021',
  575. 'ext': 'mp4',
  576. 'title': 'Genetikk og eneggede tvillinger',
  577. 'description': 'md5:3aca25dcf38ec30f0363428d2b265f8d',
  578. 'duration': 399,
  579. },
  580. }, {
  581. 'url': 'https://www.nrk.no/skole/?page=objectives&subject=naturfag&objective=K15114&mediaId=19355',
  582. 'only_matching': True,
  583. }]
  584. def _real_extract(self, url):
  585. video_id = self._match_id(url)
  586. webpage = self._download_webpage(
  587. 'https://mimir.nrk.no/plugin/1.0/static?mediaId=%s' % video_id,
  588. video_id)
  589. nrk_id = self._parse_json(
  590. self._search_regex(
  591. r'<script[^>]+type=["\']application/json["\'][^>]*>({.+?})</script>',
  592. webpage, 'application json'),
  593. video_id)['activeMedia']['psId']
  594. return self.url_result('nrk:%s' % nrk_id)