logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

gdcvault.py (8596B)


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