gdcvault.py 8.1 KB

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