You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
6.3 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. class GDCVaultIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?gdcvault\.com/play/(?P<id>\d+)/(?P<name>(\w|-)+)'
  10. _TESTS = [
  11. {
  12. 'url': 'http://www.gdcvault.com/play/1019721/Doki-Doki-Universe-Sweet-Simple',
  13. 'md5': '7ce8388f544c88b7ac11c7ab1b593704',
  14. 'info_dict': {
  15. 'id': '1019721',
  16. 'ext': 'mp4',
  17. 'title': 'Doki-Doki Universe: Sweet, Simple and Genuine (GDC Next 10)'
  18. }
  19. },
  20. {
  21. 'url': 'http://www.gdcvault.com/play/1015683/Embracing-the-Dark-Art-of',
  22. 'info_dict': {
  23. 'id': '1015683',
  24. 'ext': 'flv',
  25. 'title': 'Embracing the Dark Art of Mathematical Modeling in AI'
  26. },
  27. 'params': {
  28. 'skip_download': True, # Requires rtmpdump
  29. }
  30. },
  31. {
  32. 'url': 'http://www.gdcvault.com/play/1015301/Thexder-Meets-Windows-95-or',
  33. 'md5': 'a5eb77996ef82118afbbe8e48731b98e',
  34. 'info_dict': {
  35. 'id': '1015301',
  36. 'ext': 'flv',
  37. 'title': 'Thexder Meets Windows 95, or Writing Great Games in the Windows 95 Environment',
  38. },
  39. 'skip': 'Requires login',
  40. }
  41. ]
  42. def _parse_mp4(self, xml_description):
  43. video_formats = []
  44. mp4_video = xml_description.find('./metadata/mp4video')
  45. if mp4_video is None:
  46. return None
  47. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video.text)
  48. video_root = mobj.group('root')
  49. formats = xml_description.findall('./metadata/MBRVideos/MBRVideo')
  50. for format in formats:
  51. mobj = re.match(r'mp4\:(?P<path>.*)', format.find('streamName').text)
  52. url = video_root + mobj.group('path')
  53. vbr = format.find('bitrate').text
  54. video_formats.append({
  55. 'url': url,
  56. 'vbr': int(vbr),
  57. })
  58. return video_formats
  59. def _parse_flv(self, xml_description):
  60. video_formats = []
  61. akami_url = xml_description.find('./metadata/akamaiHost').text
  62. slide_video_path = xml_description.find('./metadata/slideVideo').text
  63. video_formats.append({
  64. 'url': 'rtmp://' + akami_url + '/' + slide_video_path,
  65. 'format_note': 'slide deck video',
  66. 'quality': -2,
  67. 'preference': -2,
  68. 'format_id': 'slides',
  69. })
  70. speaker_video_path = xml_description.find('./metadata/speakerVideo').text
  71. video_formats.append({
  72. 'url': 'rtmp://' + akami_url + '/' + speaker_video_path,
  73. 'format_note': 'speaker video',
  74. 'quality': -1,
  75. 'preference': -1,
  76. 'format_id': 'speaker',
  77. })
  78. return video_formats
  79. def _login(self, webpage_url, video_id):
  80. (username, password) = self._get_login_info()
  81. if username is None or password is None:
  82. self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
  83. return None
  84. mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
  85. login_url = mobj.group('root_url') + 'api/login.php'
  86. logout_url = mobj.group('root_url') + 'logout'
  87. login_form = {
  88. 'email': username,
  89. 'password': password,
  90. }
  91. request = compat_urllib_request.Request(login_url, compat_urllib_parse.urlencode(login_form))
  92. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  93. self._download_webpage(request, video_id, 'Logging in')
  94. start_page = self._download_webpage(webpage_url, video_id, 'Getting authenticated video page')
  95. self._download_webpage(logout_url, video_id, 'Logging out')
  96. return start_page
  97. def _real_extract(self, url):
  98. mobj = re.match(self._VALID_URL, url)
  99. video_id = mobj.group('id')
  100. webpage_url = 'http://www.gdcvault.com/play/' + video_id
  101. start_page = self._download_webpage(webpage_url, video_id)
  102. direct_url = self._search_regex(
  103. r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
  104. start_page, 'url', default=None)
  105. if direct_url:
  106. video_url = 'http://www.gdcvault.com/' + direct_url
  107. title = self._html_search_regex(
  108. r'<td><strong>Session Name</strong></td>\s*<td>(.*?)</td>',
  109. start_page, 'title')
  110. return {
  111. 'id': video_id,
  112. 'url': video_url,
  113. 'ext': 'flv',
  114. 'title': title,
  115. }
  116. xml_root = self._html_search_regex(
  117. r'<iframe src="(?P<xml_root>.*?)player.html.*?".*?</iframe>',
  118. start_page, 'xml root', default=None)
  119. if xml_root is None:
  120. # Probably need to authenticate
  121. login_res = self._login(webpage_url, video_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. r'<iframe src="(.*?)player.html.*?".*?</iframe>',
  129. start_page, 'xml root')
  130. xml_name = self._html_search_regex(
  131. r'<iframe src=".*?\?xml=(.+?\.xml).*?".*?</iframe>',
  132. start_page, 'xml filename', default=None)
  133. if xml_name is None:
  134. # Fallback to the older format
  135. xml_name = self._html_search_regex(r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>', start_page, 'xml filename')
  136. xml_decription_url = xml_root + 'xml/' + xml_name
  137. xml_description = self._download_xml(xml_decription_url, video_id)
  138. video_title = xml_description.find('./metadata/title').text
  139. video_formats = self._parse_mp4(xml_description)
  140. if video_formats is None:
  141. video_formats = self._parse_flv(xml_description)
  142. return {
  143. 'id': video_id,
  144. 'title': video_title,
  145. 'formats': video_formats,
  146. }