gdcvault.py 5.5 KB

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