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.

83 lines
2.8 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. raw_page = self._download_webpage(
  24. 'http://techtv.mit.edu/videos/%s' % video_id, video_id)
  25. clean_page = re.compile(u'<!--.*?-->', re.S).sub(u'', raw_page)
  26. base_url = self._search_regex(r'ipadUrl: \'(.+?cloudfront.net/)',
  27. raw_page, u'base url')
  28. formats_json = self._search_regex(r'bitrates: (\[.+?\])', raw_page,
  29. u'video formats')
  30. formats_mit = json.loads(formats_json)
  31. formats = [
  32. {
  33. 'format_id': f['label'],
  34. 'url': base_url + f['url'].partition(':')[2],
  35. 'ext': f['url'].partition(':')[0],
  36. 'format': f['label'],
  37. 'width': f['width'],
  38. 'vbr': f['bitrate'],
  39. }
  40. for f in formats_mit
  41. ]
  42. title = get_element_by_id('edit-title', clean_page)
  43. description = clean_html(get_element_by_id('edit-description', clean_page))
  44. thumbnail = self._search_regex(r'playlist:.*?url: \'(.+?)\'',
  45. raw_page, u'thumbnail', flags=re.DOTALL)
  46. return {'id': video_id,
  47. 'title': title,
  48. 'formats': formats,
  49. 'description': description,
  50. 'thumbnail': thumbnail,
  51. }
  52. class MITIE(TechTVMITIE):
  53. IE_NAME = u'video.mit.edu'
  54. _VALID_URL = r'https?://video\.mit\.edu/watch/(?P<title>[^/]+)'
  55. _TEST = {
  56. u'url': u'http://video.mit.edu/watch/the-government-is-profiling-you-13222/',
  57. u'file': u'21783.mp4',
  58. u'md5': u'7db01d5ccc1895fc5010e9c9e13648da',
  59. u'info_dict': {
  60. u'title': u'The Government is Profiling You',
  61. u'description': u'md5:ad5795fe1e1623b73620dbfd47df9afd',
  62. },
  63. }
  64. def _real_extract(self, url):
  65. mobj = re.match(self._VALID_URL, url)
  66. page_title = mobj.group('title')
  67. webpage = self._download_webpage(url, page_title)
  68. self.to_screen('%s: Extracting %s url' % (page_title, TechTVMITIE.IE_NAME))
  69. embed_url = self._search_regex(r'<iframe .*?src="(.+?)"', webpage,
  70. u'embed url')
  71. return self.url_result(embed_url, ie='TechTVMIT')