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.

199 lines
7.5 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. remove_end,
  6. HEADRequest,
  7. sanitized_Request,
  8. urlencode_postdata,
  9. )
  10. class GDCVaultIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?gdcvault\.com/play/(?P<id>\d+)/(?P<name>(\w|-)+)?'
  12. _NETRC_MACHINE = 'gdcvault'
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.gdcvault.com/play/1019721/Doki-Doki-Universe-Sweet-Simple',
  16. 'md5': '7ce8388f544c88b7ac11c7ab1b593704',
  17. 'info_dict': {
  18. 'id': '1019721',
  19. 'display_id': 'Doki-Doki-Universe-Sweet-Simple',
  20. 'ext': 'mp4',
  21. 'title': 'Doki-Doki Universe: Sweet, Simple and Genuine (GDC Next 10)'
  22. }
  23. },
  24. {
  25. 'url': 'http://www.gdcvault.com/play/1015683/Embracing-the-Dark-Art-of',
  26. 'info_dict': {
  27. 'id': '1015683',
  28. 'display_id': 'Embracing-the-Dark-Art-of',
  29. 'ext': 'flv',
  30. 'title': 'Embracing the Dark Art of Mathematical Modeling in AI'
  31. },
  32. 'params': {
  33. 'skip_download': True, # Requires rtmpdump
  34. }
  35. },
  36. {
  37. 'url': 'http://www.gdcvault.com/play/1015301/Thexder-Meets-Windows-95-or',
  38. 'md5': 'a5eb77996ef82118afbbe8e48731b98e',
  39. 'info_dict': {
  40. 'id': '1015301',
  41. 'display_id': 'Thexder-Meets-Windows-95-or',
  42. 'ext': 'flv',
  43. 'title': 'Thexder Meets Windows 95, or Writing Great Games in the Windows 95 Environment',
  44. },
  45. 'skip': 'Requires login',
  46. },
  47. {
  48. 'url': 'http://gdcvault.com/play/1020791/',
  49. 'only_matching': True,
  50. }
  51. ]
  52. def _parse_mp4(self, xml_description):
  53. video_formats = []
  54. mp4_video = xml_description.find('./metadata/mp4video')
  55. if mp4_video is None:
  56. return None
  57. mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video.text)
  58. video_root = mobj.group('root')
  59. formats = xml_description.findall('./metadata/MBRVideos/MBRVideo')
  60. for format in formats:
  61. mobj = re.match(r'mp4\:(?P<path>.*)', format.find('streamName').text)
  62. url = video_root + mobj.group('path')
  63. vbr = format.find('bitrate').text
  64. video_formats.append({
  65. 'url': url,
  66. 'vbr': int(vbr),
  67. })
  68. return video_formats
  69. def _parse_flv(self, xml_description):
  70. formats = []
  71. akamai_url = xml_description.find('./metadata/akamaiHost').text
  72. audios = xml_description.find('./metadata/audios')
  73. if audios is not None:
  74. for audio in audios:
  75. formats.append({
  76. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  77. 'play_path': remove_end(audio.get('url'), '.flv'),
  78. 'ext': 'flv',
  79. 'vcodec': 'none',
  80. 'format_id': audio.get('code'),
  81. })
  82. slide_video_path = xml_description.find('./metadata/slideVideo').text
  83. formats.append({
  84. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  85. 'play_path': remove_end(slide_video_path, '.flv'),
  86. 'ext': 'flv',
  87. 'format_note': 'slide deck video',
  88. 'quality': -2,
  89. 'preference': -2,
  90. 'format_id': 'slides',
  91. })
  92. speaker_video_path = xml_description.find('./metadata/speakerVideo').text
  93. formats.append({
  94. 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url,
  95. 'play_path': remove_end(speaker_video_path, '.flv'),
  96. 'ext': 'flv',
  97. 'format_note': 'speaker video',
  98. 'quality': -1,
  99. 'preference': -1,
  100. 'format_id': 'speaker',
  101. })
  102. return formats
  103. def _login(self, webpage_url, display_id):
  104. (username, password) = self._get_login_info()
  105. if username is None or password is None:
  106. self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
  107. return None
  108. mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
  109. login_url = mobj.group('root_url') + 'api/login.php'
  110. logout_url = mobj.group('root_url') + 'logout'
  111. login_form = {
  112. 'email': username,
  113. 'password': password,
  114. }
  115. request = sanitized_Request(login_url, urlencode_postdata(login_form))
  116. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  117. self._download_webpage(request, display_id, 'Logging in')
  118. start_page = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page')
  119. self._download_webpage(logout_url, display_id, 'Logging out')
  120. return start_page
  121. def _real_extract(self, url):
  122. mobj = re.match(self._VALID_URL, url)
  123. video_id = mobj.group('id')
  124. display_id = mobj.group('name') or video_id
  125. webpage_url = 'http://www.gdcvault.com/play/' + video_id
  126. start_page = self._download_webpage(webpage_url, display_id)
  127. direct_url = self._search_regex(
  128. r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
  129. start_page, 'url', default=None)
  130. if direct_url:
  131. title = self._html_search_regex(
  132. r'<td><strong>Session Name</strong></td>\s*<td>(.*?)</td>',
  133. start_page, 'title')
  134. video_url = 'http://www.gdcvault.com' + direct_url
  135. # resolve the url so that we can detect the correct extension
  136. head = self._request_webpage(HEADRequest(video_url), video_id)
  137. video_url = head.geturl()
  138. return {
  139. 'id': video_id,
  140. 'display_id': display_id,
  141. 'url': video_url,
  142. 'title': title,
  143. }
  144. PLAYER_REGEX = r'<iframe src="(?P<xml_root>.+?)/player.*?\.html.*?".*?</iframe>'
  145. xml_root = self._html_search_regex(
  146. PLAYER_REGEX, start_page, 'xml root', default=None)
  147. if xml_root is None:
  148. # Probably need to authenticate
  149. login_res = self._login(webpage_url, display_id)
  150. if login_res is None:
  151. self.report_warning('Could not login.')
  152. else:
  153. start_page = login_res
  154. # Grab the url from the authenticated page
  155. xml_root = self._html_search_regex(
  156. PLAYER_REGEX, start_page, 'xml root')
  157. xml_name = self._html_search_regex(
  158. r'<iframe src=".*?\?xml=(.+?\.xml).*?".*?</iframe>',
  159. start_page, 'xml filename', default=None)
  160. if xml_name is None:
  161. # Fallback to the older format
  162. xml_name = self._html_search_regex(
  163. r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>',
  164. start_page, 'xml filename')
  165. xml_description = self._download_xml(
  166. '%s/xml/%s' % (xml_root, xml_name), display_id)
  167. video_title = xml_description.find('./metadata/title').text
  168. video_formats = self._parse_mp4(xml_description)
  169. if video_formats is None:
  170. video_formats = self._parse_flv(xml_description)
  171. return {
  172. 'id': video_id,
  173. 'display_id': display_id,
  174. 'title': video_title,
  175. 'formats': video_formats,
  176. }