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.

134 lines
5.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. def _parse_mp4(self, xml_description):
  33. video_formats = []
  34. mp4_video = xml_description.find('./metadata/mp4video')
  35. if mp4_video is None:
  36. return None
  37. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video.text)
  38. video_root = mobj.group('root')
  39. formats = xml_description.findall('./metadata/MBRVideos/MBRVideo')
  40. for format in formats:
  41. mobj = re.match(r'mp4\:(?P<path>.*)', format.find('streamName').text)
  42. url = video_root + mobj.group('path')
  43. vbr = format.find('bitrate').text
  44. video_formats.append({
  45. 'url': url,
  46. 'vbr': int(vbr),
  47. })
  48. return video_formats
  49. def _parse_flv(self, xml_description):
  50. video_formats = []
  51. akami_url = xml_description.find('./metadata/akamaiHost').text
  52. slide_video_path = xml_description.find('./metadata/slideVideo').text
  53. video_formats.append({
  54. 'url': 'rtmp://' + akami_url + '/' + slide_video_path,
  55. 'format_note': 'slide deck video',
  56. 'quality': -2,
  57. 'preference': -2,
  58. 'format_id': 'slides',
  59. })
  60. speaker_video_path = xml_description.find('./metadata/speakerVideo').text
  61. video_formats.append({
  62. 'url': 'rtmp://' + akami_url + '/' + speaker_video_path,
  63. 'format_note': 'speaker video',
  64. 'quality': -1,
  65. 'preference': -1,
  66. 'format_id': 'speaker',
  67. })
  68. return video_formats
  69. def _login(self, webpage_url, video_id):
  70. (username, password) = self._get_login_info()
  71. if username is None or password is None:
  72. self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
  73. return None
  74. mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
  75. login_url = mobj.group('root_url') + 'api/login.php'
  76. logout_url = mobj.group('root_url') + 'logout'
  77. login_form = {
  78. 'email': username,
  79. 'password': password,
  80. }
  81. request = compat_urllib_request.Request(login_url, compat_urllib_parse.urlencode(login_form))
  82. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  83. self._download_webpage(request, video_id, 'Logging in')
  84. start_page = self._download_webpage(webpage_url, video_id, 'Getting authenticated video page')
  85. self._download_webpage(logout_url, video_id, 'Logging out')
  86. return start_page
  87. def _real_extract(self, url):
  88. mobj = re.match(self._VALID_URL, url)
  89. video_id = mobj.group('id')
  90. webpage_url = 'http://www.gdcvault.com/play/' + video_id
  91. start_page = self._download_webpage(webpage_url, video_id)
  92. xml_root = self._html_search_regex(r'<iframe src="(?P<xml_root>.*?)player.html.*?".*?</iframe>', start_page, 'xml root', None, False)
  93. if xml_root is None:
  94. # Probably need to authenticate
  95. start_page = self._login(webpage_url, video_id)
  96. if start_page is None:
  97. self.report_warning('Could not login.')
  98. else:
  99. # Grab the url from the authenticated page
  100. xml_root = self._html_search_regex(r'<iframe src="(?P<xml_root>.*?)player.html.*?".*?</iframe>', start_page, 'xml root')
  101. xml_name = self._html_search_regex(r'<iframe src=".*?\?xml=(?P<xml_file>.+?\.xml).*?".*?</iframe>', start_page, 'xml filename', None, False)
  102. if xml_name is None:
  103. # Fallback to the older format
  104. xml_name = self._html_search_regex(r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>', start_page, 'xml filename')
  105. xml_decription_url = xml_root + 'xml/' + xml_name
  106. xml_description = self._download_xml(xml_decription_url, video_id)
  107. video_title = xml_description.find('./metadata/title').text
  108. video_formats = self._parse_mp4(xml_description)
  109. if video_formats is None:
  110. video_formats = self._parse_flv(xml_description)
  111. return {
  112. 'id': video_id,
  113. 'title': video_title,
  114. 'formats': video_formats,
  115. }