gdcvault.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. HEADRequest,
  6. sanitized_Request,
  7. urlencode_postdata,
  8. )
  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. # Hard-coded hostname
  52. 'url': 'http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface',
  53. 'md5': 'a8efb6c31ed06ca8739294960b2dbabd',
  54. 'info_dict': {
  55. 'id': '1023460',
  56. 'ext': 'mp4',
  57. 'display_id': 'Tenacious-Design-and-The-Interface',
  58. 'title': 'Tenacious Design and The Interface of \'Destiny\'',
  59. },
  60. },
  61. {
  62. # Multiple audios
  63. 'url': 'http://www.gdcvault.com/play/1014631/Classic-Game-Postmortem-PAC',
  64. 'info_dict': {
  65. 'id': '1014631',
  66. 'ext': 'flv',
  67. 'title': 'How to Create a Good Game - From My Experience of Designing Pac-Man',
  68. },
  69. 'params': {
  70. 'skip_download': True, # Requires rtmpdump
  71. 'format': 'jp', # The japanese audio
  72. }
  73. },
  74. ]
  75. def _login(self, webpage_url, display_id):
  76. (username, password) = self._get_login_info()
  77. if username is None or password is None:
  78. self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
  79. return None
  80. mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
  81. login_url = mobj.group('root_url') + 'api/login.php'
  82. logout_url = mobj.group('root_url') + 'logout'
  83. login_form = {
  84. 'email': username,
  85. 'password': password,
  86. }
  87. request = sanitized_Request(login_url, urlencode_postdata(login_form))
  88. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  89. self._download_webpage(request, display_id, 'Logging in')
  90. start_page = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page')
  91. self._download_webpage(logout_url, display_id, 'Logging out')
  92. return start_page
  93. def _real_extract(self, url):
  94. mobj = re.match(self._VALID_URL, url)
  95. video_id = mobj.group('id')
  96. display_id = mobj.group('name') or video_id
  97. webpage_url = 'http://www.gdcvault.com/play/' + video_id
  98. start_page = self._download_webpage(webpage_url, display_id)
  99. direct_url = self._search_regex(
  100. r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
  101. start_page, 'url', default=None)
  102. if direct_url:
  103. title = self._html_search_regex(
  104. r'<td><strong>Session Name</strong></td>\s*<td>(.*?)</td>',
  105. start_page, 'title')
  106. video_url = 'http://www.gdcvault.com' + direct_url
  107. # resolve the url so that we can detect the correct extension
  108. head = self._request_webpage(HEADRequest(video_url), video_id)
  109. video_url = head.geturl()
  110. return {
  111. 'id': video_id,
  112. 'display_id': display_id,
  113. 'url': video_url,
  114. 'title': title,
  115. }
  116. PLAYER_REGEX = r'<iframe src="(?P<xml_root>.+?)/player.*?\.html.*?".*?</iframe>'
  117. xml_root = self._html_search_regex(
  118. PLAYER_REGEX, start_page, 'xml root', default=None)
  119. if xml_root is None:
  120. # Probably need to authenticate
  121. login_res = self._login(webpage_url, display_id)
  122. if login_res is None:
  123. self.report_warning('Could not login.')
  124. else:
  125. start_page = login_res
  126. # Grab the url from the authenticated page
  127. xml_root = self._html_search_regex(
  128. PLAYER_REGEX, start_page, 'xml root')
  129. xml_name = self._html_search_regex(
  130. r'<iframe src=".*?\?xml=(.+?\.xml).*?".*?</iframe>',
  131. start_page, 'xml filename', default=None)
  132. if xml_name is None:
  133. # Fallback to the older format
  134. xml_name = self._html_search_regex(
  135. r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>',
  136. start_page, 'xml filename')
  137. return {
  138. '_type': 'url_transparent',
  139. 'id': video_id,
  140. 'display_id': display_id,
  141. 'url': '%s/xml/%s' % (xml_root, xml_name),
  142. 'ie': 'DigitalSpeaking',
  143. }