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.

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