gdcvault.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import re
  2. from .common import InfoExtractor
  3. from .kaltura import KalturaIE
  4. from ..utils import (
  5. HEADRequest,
  6. remove_start,
  7. sanitized_Request,
  8. smuggle_url,
  9. urlencode_postdata,
  10. )
  11. class GDCVaultIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?gdcvault\.com/play/(?P<id>\d+)(?:/(?P<name>[\w-]+))?'
  13. _NETRC_MACHINE = 'gdcvault'
  14. _TESTS = [
  15. {
  16. 'url': 'http://www.gdcvault.com/play/1019721/Doki-Doki-Universe-Sweet-Simple',
  17. 'md5': '7ce8388f544c88b7ac11c7ab1b593704',
  18. 'info_dict': {
  19. 'id': '201311826596_AWNY',
  20. 'display_id': 'Doki-Doki-Universe-Sweet-Simple',
  21. 'ext': 'mp4',
  22. 'title': 'Doki-Doki Universe: Sweet, Simple and Genuine (GDC Next 10)'
  23. }
  24. },
  25. {
  26. 'url': 'http://www.gdcvault.com/play/1015683/Embracing-the-Dark-Art-of',
  27. 'info_dict': {
  28. 'id': '201203272_1330951438328RSXR',
  29. 'display_id': 'Embracing-the-Dark-Art-of',
  30. 'ext': 'flv',
  31. 'title': 'Embracing the Dark Art of Mathematical Modeling in AI'
  32. },
  33. 'params': {
  34. 'skip_download': True, # Requires rtmpdump
  35. }
  36. },
  37. {
  38. 'url': 'http://www.gdcvault.com/play/1015301/Thexder-Meets-Windows-95-or',
  39. 'md5': 'a5eb77996ef82118afbbe8e48731b98e',
  40. 'info_dict': {
  41. 'id': '1015301',
  42. 'display_id': 'Thexder-Meets-Windows-95-or',
  43. 'ext': 'flv',
  44. 'title': 'Thexder Meets Windows 95, or Writing Great Games in the Windows 95 Environment',
  45. },
  46. 'skip': 'Requires login',
  47. },
  48. {
  49. 'url': 'http://gdcvault.com/play/1020791/',
  50. 'only_matching': True,
  51. },
  52. {
  53. # Hard-coded hostname
  54. 'url': 'http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface',
  55. 'md5': 'a8efb6c31ed06ca8739294960b2dbabd',
  56. 'info_dict': {
  57. 'id': '840376_BQRC',
  58. 'ext': 'mp4',
  59. 'display_id': 'Tenacious-Design-and-The-Interface',
  60. 'title': 'Tenacious Design and The Interface of \'Destiny\'',
  61. },
  62. },
  63. {
  64. # Multiple audios
  65. 'url': 'http://www.gdcvault.com/play/1014631/Classic-Game-Postmortem-PAC',
  66. 'info_dict': {
  67. 'id': '12396_1299111843500GMPX',
  68. 'ext': 'mp4',
  69. 'title': 'How to Create a Good Game - From My Experience of Designing Pac-Man',
  70. },
  71. # 'params': {
  72. # 'skip_download': True, # Requires rtmpdump
  73. # 'format': 'jp', # The japanese audio
  74. # }
  75. },
  76. {
  77. # gdc-player.html
  78. 'url': 'http://www.gdcvault.com/play/1435/An-American-engine-in-Tokyo',
  79. 'info_dict': {
  80. 'id': '9350_1238021887562UHXB',
  81. 'display_id': 'An-American-engine-in-Tokyo',
  82. 'ext': 'mp4',
  83. 'title': 'An American Engine in Tokyo:/nThe collaboration of Epic Games and Square Enix/nFor THE LAST REMINANT',
  84. },
  85. },
  86. {
  87. # Kaltura Embed
  88. 'url': 'https://www.gdcvault.com/play/1026180/Mastering-the-Apex-of-Scaling',
  89. 'info_dict': {
  90. 'id': '0_h1fg8j3p',
  91. 'ext': 'mp4',
  92. 'title': 'Mastering the Apex of Scaling Game Servers (Presented by Multiplay)',
  93. 'timestamp': 1554401811,
  94. 'upload_date': '20190404',
  95. 'uploader_id': 'joe@blazestreaming.com',
  96. },
  97. 'params': {
  98. 'format': 'mp4-408',
  99. },
  100. },
  101. {
  102. # Kaltura embed, whitespace between quote and embedded URL in iframe's src
  103. 'url': 'https://www.gdcvault.com/play/1025699',
  104. 'info_dict': {
  105. 'id': '0_zagynv0a',
  106. 'ext': 'mp4',
  107. 'title': 'Tech Toolbox',
  108. 'upload_date': '20190408',
  109. 'uploader_id': 'joe@blazestreaming.com',
  110. 'timestamp': 1554764629,
  111. },
  112. 'params': {
  113. 'skip_download': True,
  114. },
  115. },
  116. {
  117. # HTML5 video
  118. 'url': 'http://www.gdcvault.com/play/1014846/Conference-Keynote-Shigeru',
  119. 'only_matching': True,
  120. },
  121. ]
  122. def _login(self, webpage_url, display_id):
  123. username, password = self._get_login_info()
  124. if username is None or password is None:
  125. self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
  126. return None
  127. mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
  128. login_url = mobj.group('root_url') + 'api/login.php'
  129. logout_url = mobj.group('root_url') + 'logout'
  130. login_form = {
  131. 'email': username,
  132. 'password': password,
  133. }
  134. request = sanitized_Request(login_url, urlencode_postdata(login_form))
  135. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  136. self._download_webpage(request, display_id, 'Logging in')
  137. start_page = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page')
  138. self._download_webpage(logout_url, display_id, 'Logging out')
  139. return start_page
  140. def _real_extract(self, url):
  141. video_id, name = self._match_valid_url(url).groups()
  142. display_id = name or video_id
  143. webpage_url = 'http://www.gdcvault.com/play/' + video_id
  144. start_page = self._download_webpage(webpage_url, display_id)
  145. direct_url = self._search_regex(
  146. r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
  147. start_page, 'url', default=None)
  148. if direct_url:
  149. title = self._html_search_regex(
  150. r'<td><strong>Session Name:?</strong></td>\s*<td>(.*?)</td>',
  151. start_page, 'title')
  152. video_url = 'http://www.gdcvault.com' + direct_url
  153. # resolve the url so that we can detect the correct extension
  154. video_url = self._request_webpage(
  155. HEADRequest(video_url), video_id).geturl()
  156. return {
  157. 'id': video_id,
  158. 'display_id': display_id,
  159. 'url': video_url,
  160. 'title': title,
  161. }
  162. embed_url = KalturaIE._extract_url(start_page)
  163. if embed_url:
  164. embed_url = smuggle_url(embed_url, {'source_url': url})
  165. ie_key = 'Kaltura'
  166. else:
  167. PLAYER_REGEX = r'<iframe src="(?P<xml_root>.+?)/(?:gdc-)?player.*?\.html.*?".*?</iframe>'
  168. xml_root = self._html_search_regex(
  169. PLAYER_REGEX, start_page, 'xml root', default=None)
  170. if xml_root is None:
  171. # Probably need to authenticate
  172. login_res = self._login(webpage_url, display_id)
  173. if login_res is None:
  174. self.report_warning('Could not login.')
  175. else:
  176. start_page = login_res
  177. # Grab the url from the authenticated page
  178. xml_root = self._html_search_regex(
  179. PLAYER_REGEX, start_page, 'xml root')
  180. xml_name = self._html_search_regex(
  181. r'<iframe src=".*?\?xml(?:=|URL=xml/)(.+?\.xml).*?".*?</iframe>',
  182. start_page, 'xml filename', default=None)
  183. if not xml_name:
  184. info = self._parse_html5_media_entries(url, start_page, video_id)[0]
  185. info.update({
  186. 'title': remove_start(self._search_regex(
  187. r'>Session Name:\s*<.*?>\s*<td>(.+?)</td>', start_page,
  188. 'title', default=None) or self._og_search_title(
  189. start_page, default=None), 'GDC Vault - '),
  190. 'id': video_id,
  191. 'display_id': display_id,
  192. })
  193. return info
  194. embed_url = '%s/xml/%s' % (xml_root, xml_name)
  195. ie_key = 'DigitallySpeaking'
  196. return {
  197. '_type': 'url_transparent',
  198. 'id': video_id,
  199. 'display_id': display_id,
  200. 'url': embed_url,
  201. 'ie_key': ie_key,
  202. }