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.

166 lines
6.2 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils 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. }
  40. ]
  41. def _parse_mp4(self, xml_description):
  42. video_formats = []
  43. mp4_video = xml_description.find('./metadata/mp4video')
  44. if mp4_video is None:
  45. return None
  46. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video.text)
  47. video_root = mobj.group('root')
  48. formats = xml_description.findall('./metadata/MBRVideos/MBRVideo')
  49. for format in formats:
  50. mobj = re.match(r'mp4\:(?P<path>.*)', format.find('streamName').text)
  51. url = video_root + mobj.group('path')
  52. vbr = format.find('bitrate').text
  53. video_formats.append({
  54. 'url': url,
  55. 'vbr': int(vbr),
  56. })
  57. return video_formats
  58. def _parse_flv(self, xml_description):
  59. video_formats = []
  60. akami_url = xml_description.find('./metadata/akamaiHost').text
  61. slide_video_path = xml_description.find('./metadata/slideVideo').text
  62. video_formats.append({
  63. 'url': 'rtmp://' + akami_url + '/' + slide_video_path,
  64. 'format_note': 'slide deck video',
  65. 'quality': -2,
  66. 'preference': -2,
  67. 'format_id': 'slides',
  68. })
  69. speaker_video_path = xml_description.find('./metadata/speakerVideo').text
  70. video_formats.append({
  71. 'url': 'rtmp://' + akami_url + '/' + speaker_video_path,
  72. 'format_note': 'speaker video',
  73. 'quality': -1,
  74. 'preference': -1,
  75. 'format_id': 'speaker',
  76. })
  77. return video_formats
  78. def _login(self, webpage_url, video_id):
  79. (username, password) = self._get_login_info()
  80. if username is None or password is None:
  81. self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
  82. return None
  83. mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
  84. login_url = mobj.group('root_url') + 'api/login.php'
  85. logout_url = mobj.group('root_url') + 'logout'
  86. login_form = {
  87. 'email': username,
  88. 'password': password,
  89. }
  90. request = compat_urllib_request.Request(login_url, compat_urllib_parse.urlencode(login_form))
  91. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  92. self._download_webpage(request, video_id, 'Logging in')
  93. start_page = self._download_webpage(webpage_url, video_id, 'Getting authenticated video page')
  94. self._download_webpage(logout_url, video_id, 'Logging out')
  95. return start_page
  96. def _real_extract(self, url):
  97. mobj = re.match(self._VALID_URL, url)
  98. video_id = mobj.group('id')
  99. webpage_url = 'http://www.gdcvault.com/play/' + video_id
  100. start_page = self._download_webpage(webpage_url, video_id)
  101. direct_url = self._search_regex(
  102. r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
  103. start_page, 'url', default=None)
  104. if direct_url:
  105. video_url = 'http://www.gdcvault.com/' + direct_url
  106. title = self._html_search_regex(
  107. r'<td><strong>Session Name</strong></td>\s*<td>(.*?)</td>',
  108. start_page, 'title')
  109. return {
  110. 'id': video_id,
  111. 'url': video_url,
  112. 'ext': 'flv',
  113. 'title': title,
  114. }
  115. xml_root = self._html_search_regex(
  116. r'<iframe src="(?P<xml_root>.*?)player.html.*?".*?</iframe>',
  117. start_page, 'xml root', default=None)
  118. if xml_root is None:
  119. # Probably need to authenticate
  120. login_res = self._login(webpage_url, video_id)
  121. if login_res is None:
  122. self.report_warning('Could not login.')
  123. else:
  124. start_page = login_res
  125. # Grab the url from the authenticated page
  126. xml_root = self._html_search_regex(
  127. r'<iframe src="(.*?)player.html.*?".*?</iframe>',
  128. start_page, 'xml root')
  129. xml_name = self._html_search_regex(
  130. r'<iframe src=".*?\?xml=(.+?\.xml).*?".*?</iframe>',
  131. start_page, 'xml filename', default=None)
  132. if xml_name is None:
  133. # Fallback to the older format
  134. xml_name = self._html_search_regex(r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>', start_page, 'xml filename')
  135. xml_decription_url = xml_root + 'xml/' + xml_name
  136. xml_description = self._download_xml(xml_decription_url, video_id)
  137. video_title = xml_description.find('./metadata/title').text
  138. video_formats = self._parse_mp4(xml_description)
  139. if video_formats is None:
  140. video_formats = self._parse_flv(xml_description)
  141. return {
  142. 'id': video_id,
  143. 'title': video_title,
  144. 'formats': video_formats,
  145. }