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.

74 lines
2.6 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 = json.loads(formats_json)
  31. formats = sorted(formats, key=lambda f: f['bitrate'])
  32. title = get_element_by_id('edit-title', clean_page)
  33. description = clean_html(get_element_by_id('edit-description', clean_page))
  34. thumbnail = self._search_regex(r'playlist:.*?url: \'(.+?)\'',
  35. raw_page, u'thumbnail', flags=re.DOTALL)
  36. return {'id': video_id,
  37. 'title': title,
  38. 'url': base_url + formats[-1]['url'].replace('mp4:', ''),
  39. 'ext': 'mp4',
  40. 'description': description,
  41. 'thumbnail': thumbnail,
  42. }
  43. class MITIE(TechTVMITIE):
  44. IE_NAME = u'video.mit.edu'
  45. _VALID_URL = r'https?://video\.mit\.edu/watch/(?P<title>[^/]+)'
  46. _TEST = {
  47. u'url': u'http://video.mit.edu/watch/the-government-is-profiling-you-13222/',
  48. u'file': u'21783.mp4',
  49. u'md5': u'7db01d5ccc1895fc5010e9c9e13648da',
  50. u'info_dict': {
  51. u'title': u'The Government is Profiling You',
  52. u'description': u'md5:ad5795fe1e1623b73620dbfd47df9afd',
  53. },
  54. }
  55. def _real_extract(self, url):
  56. mobj = re.match(self._VALID_URL, url)
  57. page_title = mobj.group('title')
  58. webpage = self._download_webpage(url, page_title)
  59. self.to_screen('%s: Extracting %s url' % (page_title, TechTVMITIE.IE_NAME))
  60. embed_url = self._search_regex(r'<iframe .*?src="(.+?)"', webpage,
  61. u'embed url')
  62. return self.url_result(embed_url, ie='TechTVMIT')