nobelprize.py 2.0 KB

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