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.

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