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.

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