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.

158 lines
6.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from .youtube import YoutubeIE
  6. from ..utils import (
  7. compat_urlparse,
  8. clean_html,
  9. ExtractorError,
  10. get_element_by_id,
  11. )
  12. class TechTVMITIE(InfoExtractor):
  13. IE_NAME = 'techtv.mit.edu'
  14. _VALID_URL = r'https?://techtv\.mit\.edu/(videos|embeds)/(?P<id>\d+)'
  15. _TEST = {
  16. 'url': 'http://techtv.mit.edu/videos/25418-mit-dna-learning-center-set',
  17. 'md5': '1f8cb3e170d41fd74add04d3c9330e5f',
  18. 'info_dict': {
  19. 'id': '25418',
  20. 'ext': 'mp4',
  21. 'title': 'MIT DNA Learning Center Set',
  22. 'description': 'md5:82313335e8a8a3f243351ba55bc1b474',
  23. },
  24. }
  25. def _real_extract(self, url):
  26. mobj = re.match(self._VALID_URL, url)
  27. video_id = mobj.group('id')
  28. raw_page = self._download_webpage(
  29. 'http://techtv.mit.edu/videos/%s' % video_id, video_id)
  30. clean_page = re.compile(r'<!--.*?-->', re.S).sub('', raw_page)
  31. base_url = self._search_regex(
  32. r'ipadUrl: \'(.+?cloudfront.net/)', raw_page, 'base url')
  33. formats_json = self._search_regex(
  34. r'bitrates: (\[.+?\])', raw_page, 'video formats')
  35. formats_mit = json.loads(formats_json)
  36. formats = [
  37. {
  38. 'format_id': f['label'],
  39. 'url': base_url + f['url'].partition(':')[2],
  40. 'ext': f['url'].partition(':')[0],
  41. 'format': f['label'],
  42. 'width': f['width'],
  43. 'vbr': f['bitrate'],
  44. }
  45. for f in formats_mit
  46. ]
  47. title = get_element_by_id('edit-title', clean_page)
  48. description = clean_html(get_element_by_id('edit-description', clean_page))
  49. thumbnail = self._search_regex(
  50. r'playlist:.*?url: \'(.+?)\'',
  51. raw_page, 'thumbnail', flags=re.DOTALL)
  52. return {
  53. 'id': video_id,
  54. 'title': title,
  55. 'formats': formats,
  56. 'description': description,
  57. 'thumbnail': thumbnail,
  58. }
  59. class MITIE(TechTVMITIE):
  60. IE_NAME = 'video.mit.edu'
  61. _VALID_URL = r'https?://video\.mit\.edu/watch/(?P<title>[^/]+)'
  62. _TEST = {
  63. 'url': 'http://video.mit.edu/watch/the-government-is-profiling-you-13222/',
  64. 'md5': '7db01d5ccc1895fc5010e9c9e13648da',
  65. 'info_dict': {
  66. 'id': '21783',
  67. 'ext': 'mp4',
  68. 'title': 'The Government is Profiling You',
  69. 'description': 'md5:ad5795fe1e1623b73620dbfd47df9afd',
  70. },
  71. }
  72. def _real_extract(self, url):
  73. mobj = re.match(self._VALID_URL, url)
  74. page_title = mobj.group('title')
  75. webpage = self._download_webpage(url, page_title)
  76. embed_url = self._search_regex(
  77. r'<iframe .*?src="(.+?)"', webpage, 'embed url')
  78. return self.url_result(embed_url, ie='TechTVMIT')
  79. class OCWMITIE(InfoExtractor):
  80. IE_NAME = 'ocw.mit.edu'
  81. _VALID_URL = r'^http://ocw\.mit\.edu/courses/(?P<topic>[a-z0-9\-]+)'
  82. _BASE_URL = 'http://ocw.mit.edu/'
  83. _TESTS = [
  84. {
  85. 'url': 'http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-041-probabilistic-systems-analysis-and-applied-probability-fall-2010/video-lectures/lecture-7-multiple-variables-expectations-independence/',
  86. 'info_dict': {
  87. 'id': 'EObHWIEKGjA',
  88. 'ext': 'mp4',
  89. 'title': 'Lecture 7: Multiple Discrete Random Variables: Expectations, Conditioning, Independence',
  90. 'description': 'In this lecture, the professor discussed multiple random variables, expectations, and binomial distribution.',
  91. #'subtitles': 'http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-041-probabilistic-systems-analysis-and-applied-probability-fall-2010/video-lectures/lecture-7-multiple-variables-expectations-independence/MIT6_041F11_lec07_300k.mp4.srt'
  92. }
  93. },
  94. {
  95. 'url': 'http://ocw.mit.edu/courses/mathematics/18-01sc-single-variable-calculus-fall-2010/1.-differentiation/part-a-definition-and-basic-rules/session-1-introduction-to-derivatives/',
  96. 'info_dict': {
  97. 'id': '7K1sB05pE0A',
  98. 'ext': 'mp4',
  99. 'title': 'Session 1: Introduction to Derivatives',
  100. 'description': 'This section contains lecture video excerpts, lecture notes, an interactive mathlet with supporting documents, and problem solving videos.',
  101. #'subtitles': 'http://ocw.mit.edu//courses/mathematics/18-01sc-single-variable-calculus-fall-2010/ocw-18.01-f07-lec01_300k.SRT'
  102. }
  103. }
  104. ]
  105. def _real_extract(self, url):
  106. mobj = re.match(self._VALID_URL, url)
  107. topic = mobj.group('topic')
  108. webpage = self._download_webpage(url, topic)
  109. title = self._html_search_meta('WT.cg_s', webpage)
  110. description = self._html_search_meta('Description', webpage)
  111. # search for call to ocw_embed_chapter_media(container_id, media_url, provider, page_url, image_url, start, stop, captions_file)
  112. embed_chapter_media = re.search(r'ocw_embed_chapter_media\((.+?)\)', webpage)
  113. if embed_chapter_media:
  114. metadata = re.sub(r'[\'"]', '', embed_chapter_media.group(1))
  115. metadata = re.split(r', ?', metadata)
  116. yt = metadata[1]
  117. subs = compat_urlparse.urljoin(self._BASE_URL, metadata[7])
  118. else:
  119. # search for call to ocw_embed_chapter_media(container_id, media_url, provider, page_url, image_url, captions_file)
  120. embed_media = re.search(r'ocw_embed_media\((.+?)\)', webpage)
  121. if embed_media:
  122. metadata = re.sub(r'[\'"]', '', embed_media.group(1))
  123. metadata = re.split(r', ?', metadata)
  124. yt = metadata[1]
  125. subs = compat_urlparse.urljoin(self._BASE_URL, metadata[5])
  126. else:
  127. raise ExtractorError('Unable to find embedded YouTube video.')
  128. video_id = YoutubeIE.extract_id(yt)
  129. return {
  130. '_type': 'url_transparent',
  131. 'id': video_id,
  132. 'title': title,
  133. 'description': description,
  134. 'url': yt,
  135. 'url_transparent'
  136. 'subtitles': subs,
  137. 'ie_key': 'Youtube',
  138. }