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.

199 lines
7.5 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. remove_end,
  10. HEADRequest,
  11. )
  12. class GDCVaultIE(InfoExtractor):
  13. _VALID_URL = r'https?://(?:www\.)?gdcvault\.com/play/(?P<id>\d+)/(?P<name>(\w|-)+)?'
  14. _NETRC_MACHINE = 'gdcvault'
  15. _TESTS = [
  16. {
  17. 'url': 'http://www.gdcvault.com/play/1019721/Doki-Doki-Universe-Sweet-Simple',
  18. 'md5': '7ce8388f544c88b7ac11c7ab1b593704',
  19. 'info_dict': {
  20. 'id': '1019721',
  21. 'display_id': 'Doki-Doki-Universe-Sweet-Simple',
  22. 'ext': 'mp4',
  23. 'title': 'Doki-Doki Universe: Sweet, Simple and Genuine (GDC Next 10)'
  24. }
  25. },
  26. {
  27. 'url': 'http://www.gdcvault.com/play/1015683/Embracing-the-Dark-Art-of',
  28. 'info_dict': {
  29. 'id': '1015683',
  30. 'display_id': 'Embracing-the-Dark-Art-of',
  31. 'ext': 'flv',
  32. 'title': 'Embracing the Dark Art of Mathematical Modeling in AI'
  33. },
  34. 'params': {
  35. 'skip_download': True, # Requires rtmpdump
  36. }
  37. },
  38. {
  39. 'url': 'http://www.gdcvault.com/play/1015301/Thexder-Meets-Windows-95-or',
  40. 'md5': 'a5eb77996ef82118afbbe8e48731b98e',
  41. 'info_dict': {
  42. 'id': '1015301',
  43. 'display_id': 'Thexder-Meets-Windows-95-or',
  44. 'ext': 'flv',
  45. 'title': 'Thexder Meets Windows 95, or Writing Great Games in the Windows 95 Environment',
  46. },
  47. 'skip': 'Requires login',
  48. },
  49. {
  50. 'url': 'http://gdcvault.com/play/1020791/',
  51. 'only_matching': True,
  52. }
  53. ]
  54. def _parse_mp4(self, xml_description):
  55. video_formats = []
  56. mp4_video = xml_description.find('./metadata/mp4video')
  57. if mp4_video is None:
  58. return None
  59. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video.text)
  60. video_root = mobj.group('root')
  61. formats = xml_description.findall('./metadata/MBRVideos/MBRVideo')
  62. for format in formats:
  63. mobj = re.match(r'mp4\:(?P<path>.*)', format.find('streamName').text)
  64. url = video_root + mobj.group('path')
  65. vbr = format.find('bitrate').text
  66. video_formats.append({
  67. 'url': url,
  68. 'vbr': int(vbr),
  69. })
  70. return video_formats
  71. def _parse_flv(self, xml_description):
  72. formats = []
  73. akamai_url = xml_description.find('./metadata/akamaiHost').text
  74. audios = xml_description.find('./metadata/audios')
  75. if audios is not None:
  76. for audio in audios:
  77. formats.append({
  78. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  79. 'play_path': remove_end(audio.get('url'), '.flv'),
  80. 'ext': 'flv',
  81. 'vcodec': 'none',
  82. 'format_id': audio.get('code'),
  83. })
  84. slide_video_path = xml_description.find('./metadata/slideVideo').text
  85. formats.append({
  86. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  87. 'play_path': remove_end(slide_video_path, '.flv'),
  88. 'ext': 'flv',
  89. 'format_note': 'slide deck video',
  90. 'quality': -2,
  91. 'preference': -2,
  92. 'format_id': 'slides',
  93. })
  94. speaker_video_path = xml_description.find('./metadata/speakerVideo').text
  95. formats.append({
  96. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  97. 'play_path': remove_end(speaker_video_path, '.flv'),
  98. 'ext': 'flv',
  99. 'format_note': 'speaker video',
  100. 'quality': -1,
  101. 'preference': -1,
  102. 'format_id': 'speaker',
  103. })
  104. return formats
  105. def _login(self, webpage_url, display_id):
  106. (username, password) = self._get_login_info()
  107. if username is None or password is None:
  108. self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
  109. return None
  110. mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
  111. login_url = mobj.group('root_url') + 'api/login.php'
  112. logout_url = mobj.group('root_url') + 'logout'
  113. login_form = {
  114. 'email': username,
  115. 'password': password,
  116. }
  117. request = compat_urllib_request.Request(login_url, compat_urllib_parse.urlencode(login_form))
  118. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  119. self._download_webpage(request, display_id, 'Logging in')
  120. start_page = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page')
  121. self._download_webpage(logout_url, display_id, 'Logging out')
  122. return start_page
  123. def _real_extract(self, url):
  124. mobj = re.match(self._VALID_URL, url)
  125. video_id = mobj.group('id')
  126. display_id = mobj.group('name') or video_id
  127. webpage_url = 'http://www.gdcvault.com/play/' + video_id
  128. start_page = self._download_webpage(webpage_url, display_id)
  129. direct_url = self._search_regex(
  130. r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
  131. start_page, 'url', default=None)
  132. if direct_url:
  133. title = self._html_search_regex(
  134. r'<td><strong>Session Name</strong></td>\s*<td>(.*?)</td>',
  135. start_page, 'title')
  136. video_url = 'http://www.gdcvault.com' + direct_url
  137. # resolve the url so that we can detect the correct extension
  138. head = self._request_webpage(HEADRequest(video_url), video_id)
  139. video_url = head.geturl()
  140. return {
  141. 'id': video_id,
  142. 'display_id': display_id,
  143. 'url': video_url,
  144. 'title': title,
  145. }
  146. xml_root = self._html_search_regex(
  147. r'<iframe src="(?P<xml_root>.*?)player.html.*?".*?</iframe>',
  148. start_page, 'xml root', default=None)
  149. if xml_root is None:
  150. # Probably need to authenticate
  151. login_res = self._login(webpage_url, display_id)
  152. if login_res is None:
  153. self.report_warning('Could not login.')
  154. else:
  155. start_page = login_res
  156. # Grab the url from the authenticated page
  157. xml_root = self._html_search_regex(
  158. r'<iframe src="(.*?)player.html.*?".*?</iframe>',
  159. start_page, 'xml root')
  160. xml_name = self._html_search_regex(
  161. r'<iframe src=".*?\?xml=(.+?\.xml).*?".*?</iframe>',
  162. start_page, 'xml filename', default=None)
  163. if xml_name is None:
  164. # Fallback to the older format
  165. xml_name = self._html_search_regex(r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>', start_page, 'xml filename')
  166. xml_description_url = xml_root + 'xml/' + xml_name
  167. xml_description = self._download_xml(xml_description_url, display_id)
  168. video_title = xml_description.find('./metadata/title').text
  169. video_formats = self._parse_mp4(xml_description)
  170. if video_formats is None:
  171. video_formats = self._parse_flv(xml_description)
  172. return {
  173. 'id': video_id,
  174. 'display_id': display_id,
  175. 'title': video_title,
  176. 'formats': video_formats,
  177. }