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.

62 lines
2.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. js_to_json,
  6. mimetype2ext,
  7. determine_ext,
  8. update_url_query,
  9. get_element_by_attribute,
  10. int_or_none,
  11. )
  12. class NobelPrizeIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?nobelprize\.org/mediaplayer.*?\bid=(?P<id>\d+)'
  14. _TEST = {
  15. 'url': 'http://www.nobelprize.org/mediaplayer/?id=2636',
  16. 'md5': '04c81e5714bb36cc4e2232fee1d8157f',
  17. 'info_dict': {
  18. 'id': '2636',
  19. 'ext': 'mp4',
  20. 'title': 'Announcement of the 2016 Nobel Prize in Physics',
  21. 'description': 'md5:05beba57f4f5a4bbd4cf2ef28fcff739',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(url, video_id)
  27. media = self._parse_json(self._search_regex(
  28. r'(?s)var\s*config\s*=\s*({.+?});', webpage,
  29. 'config'), video_id, js_to_json)['media']
  30. title = media['title']
  31. formats = []
  32. for source in media.get('source', []):
  33. source_src = source.get('src')
  34. if not source_src:
  35. continue
  36. ext = mimetype2ext(source.get('type')) or determine_ext(source_src)
  37. if ext == 'm3u8':
  38. formats.extend(self._extract_m3u8_formats(
  39. source_src, video_id, 'mp4', 'm3u8_native',
  40. m3u8_id='hls', fatal=False))
  41. elif ext == 'f4m':
  42. formats.extend(self._extract_f4m_formats(
  43. update_url_query(source_src, {'hdcore': '3.7.0'}),
  44. video_id, f4m_id='hds', fatal=False))
  45. else:
  46. formats.append({
  47. 'url': source_src,
  48. })
  49. self._sort_formats(formats)
  50. return {
  51. 'id': video_id,
  52. 'title': title,
  53. 'description': get_element_by_attribute('itemprop', 'description', webpage),
  54. 'duration': int_or_none(media.get('duration')),
  55. 'formats': formats,
  56. }