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.

76 lines
2.7 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. get_element_by_id,
  7. )
  8. class TechTVMITIE(InfoExtractor):
  9. IE_NAME = u'techtv.mit.edu'
  10. _VALID_URL = r'https?://techtv\.mit\.edu/(videos|embeds)/(?P<id>\d+)'
  11. _TEST = {
  12. u'url': u'http://techtv.mit.edu/videos/25418-mit-dna-learning-center-set',
  13. u'file': u'25418.mp4',
  14. u'md5': u'1f8cb3e170d41fd74add04d3c9330e5f',
  15. u'info_dict': {
  16. u'title': u'MIT DNA Learning Center Set',
  17. u'description': u'md5:82313335e8a8a3f243351ba55bc1b474',
  18. },
  19. }
  20. def _real_extract(self, url):
  21. mobj = re.match(self._VALID_URL, url)
  22. video_id = mobj.group('id')
  23. webpage = self._download_webpage(
  24. 'http://techtv.mit.edu/videos/%s' % video_id, video_id)
  25. embed_page = self._download_webpage(
  26. 'http://techtv.mit.edu/embeds/%s/' % video_id, video_id,
  27. note=u'Downloading embed page')
  28. base_url = self._search_regex(r'ipadUrl: \'(.+?cloudfront.net/)',
  29. embed_page, u'base url')
  30. formats_json = self._search_regex(r'bitrates: (\[.+?\])', embed_page,
  31. u'video formats')
  32. formats = json.loads(formats_json)
  33. formats = sorted(formats, key=lambda f: f['bitrate'])
  34. title = get_element_by_id('edit-title', webpage)
  35. description = clean_html(get_element_by_id('edit-description', webpage))
  36. thumbnail = self._search_regex(r'playlist:.*?url: \'(.+?)\'',
  37. embed_page, u'thumbnail', flags=re.DOTALL)
  38. return {'id': video_id,
  39. 'title': title,
  40. 'url': base_url + formats[-1]['url'].replace('mp4:', ''),
  41. 'ext': 'mp4',
  42. 'description': description,
  43. 'thumbnail': thumbnail,
  44. }
  45. class MITIE(TechTVMITIE):
  46. IE_NAME = u'video.mit.edu'
  47. _VALID_URL = r'https?://video\.mit\.edu/watch/(?P<title>[^/]+)'
  48. _TEST = {
  49. u'url': u'http://video.mit.edu/watch/the-government-is-profiling-you-13222/',
  50. u'file': u'21783.mp4',
  51. u'md5': u'7db01d5ccc1895fc5010e9c9e13648da',
  52. u'info_dict': {
  53. u'title': u'The Government is Profiling You',
  54. u'description': u'md5:ad5795fe1e1623b73620dbfd47df9afd',
  55. },
  56. }
  57. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. page_title = mobj.group('title')
  60. webpage = self._download_webpage(url, page_title)
  61. self.to_screen('%s: Extracting %s url' % (page_title, TechTVMITIE.IE_NAME))
  62. embed_url = self._search_regex(r'<iframe .*?src="(.+?)"', webpage,
  63. u'embed url')
  64. return self.url_result(embed_url, ie='TechTVMIT')