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.

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