]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gdcvault.py
Update upstream source from tag 'upstream/2020.03.24'
[youtubedl] / youtube_dl / extractor / gdcvault.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from .kaltura import KalturaIE
7 from ..utils import (
8 HEADRequest,
9 sanitized_Request,
10 smuggle_url,
11 urlencode_postdata,
12 )
13
14
15 class GDCVaultIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?gdcvault\.com/play/(?P<id>\d+)(?:/(?P<name>[\w-]+))?'
17 _NETRC_MACHINE = 'gdcvault'
18 _TESTS = [
19 {
20 'url': 'http://www.gdcvault.com/play/1019721/Doki-Doki-Universe-Sweet-Simple',
21 'md5': '7ce8388f544c88b7ac11c7ab1b593704',
22 'info_dict': {
23 'id': '201311826596_AWNY',
24 'display_id': 'Doki-Doki-Universe-Sweet-Simple',
25 'ext': 'mp4',
26 'title': 'Doki-Doki Universe: Sweet, Simple and Genuine (GDC Next 10)'
27 }
28 },
29 {
30 'url': 'http://www.gdcvault.com/play/1015683/Embracing-the-Dark-Art-of',
31 'info_dict': {
32 'id': '201203272_1330951438328RSXR',
33 'display_id': 'Embracing-the-Dark-Art-of',
34 'ext': 'flv',
35 'title': 'Embracing the Dark Art of Mathematical Modeling in AI'
36 },
37 'params': {
38 'skip_download': True, # Requires rtmpdump
39 }
40 },
41 {
42 'url': 'http://www.gdcvault.com/play/1015301/Thexder-Meets-Windows-95-or',
43 'md5': 'a5eb77996ef82118afbbe8e48731b98e',
44 'info_dict': {
45 'id': '1015301',
46 'display_id': 'Thexder-Meets-Windows-95-or',
47 'ext': 'flv',
48 'title': 'Thexder Meets Windows 95, or Writing Great Games in the Windows 95 Environment',
49 },
50 'skip': 'Requires login',
51 },
52 {
53 'url': 'http://gdcvault.com/play/1020791/',
54 'only_matching': True,
55 },
56 {
57 # Hard-coded hostname
58 'url': 'http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface',
59 'md5': 'a8efb6c31ed06ca8739294960b2dbabd',
60 'info_dict': {
61 'id': '840376_BQRC',
62 'ext': 'mp4',
63 'display_id': 'Tenacious-Design-and-The-Interface',
64 'title': 'Tenacious Design and The Interface of \'Destiny\'',
65 },
66 },
67 {
68 # Multiple audios
69 'url': 'http://www.gdcvault.com/play/1014631/Classic-Game-Postmortem-PAC',
70 'info_dict': {
71 'id': '12396_1299111843500GMPX',
72 'ext': 'mp4',
73 'title': 'How to Create a Good Game - From My Experience of Designing Pac-Man',
74 },
75 # 'params': {
76 # 'skip_download': True, # Requires rtmpdump
77 # 'format': 'jp', # The japanese audio
78 # }
79 },
80 {
81 # gdc-player.html
82 'url': 'http://www.gdcvault.com/play/1435/An-American-engine-in-Tokyo',
83 'info_dict': {
84 'id': '9350_1238021887562UHXB',
85 'display_id': 'An-American-engine-in-Tokyo',
86 'ext': 'mp4',
87 'title': 'An American Engine in Tokyo:/nThe collaboration of Epic Games and Square Enix/nFor THE LAST REMINANT',
88 },
89 },
90 {
91 # Kaltura Embed
92 'url': 'https://www.gdcvault.com/play/1026180/Mastering-the-Apex-of-Scaling',
93 'info_dict': {
94 'id': '0_h1fg8j3p',
95 'ext': 'mp4',
96 'title': 'Mastering the Apex of Scaling Game Servers (Presented by Multiplay)',
97 'timestamp': 1554401811,
98 'upload_date': '20190404',
99 'uploader_id': 'joe@blazestreaming.com',
100 },
101 'params': {
102 'format': 'mp4-408',
103 },
104 },
105 ]
106
107 def _login(self, webpage_url, display_id):
108 username, password = self._get_login_info()
109 if username is None or password is None:
110 self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
111 return None
112
113 mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
114 login_url = mobj.group('root_url') + 'api/login.php'
115 logout_url = mobj.group('root_url') + 'logout'
116
117 login_form = {
118 'email': username,
119 'password': password,
120 }
121
122 request = sanitized_Request(login_url, urlencode_postdata(login_form))
123 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
124 self._download_webpage(request, display_id, 'Logging in')
125 start_page = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page')
126 self._download_webpage(logout_url, display_id, 'Logging out')
127
128 return start_page
129
130 def _real_extract(self, url):
131 video_id, name = re.match(self._VALID_URL, url).groups()
132 display_id = name or video_id
133
134 webpage_url = 'http://www.gdcvault.com/play/' + video_id
135 start_page = self._download_webpage(webpage_url, display_id)
136
137 direct_url = self._search_regex(
138 r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
139 start_page, 'url', default=None)
140 if direct_url:
141 title = self._html_search_regex(
142 r'<td><strong>Session Name:?</strong></td>\s*<td>(.*?)</td>',
143 start_page, 'title')
144 video_url = 'http://www.gdcvault.com' + direct_url
145 # resolve the url so that we can detect the correct extension
146 video_url = self._request_webpage(
147 HEADRequest(video_url), video_id).geturl()
148
149 return {
150 'id': video_id,
151 'display_id': display_id,
152 'url': video_url,
153 'title': title,
154 }
155
156 embed_url = KalturaIE._extract_url(start_page)
157 if embed_url:
158 embed_url = smuggle_url(embed_url, {'source_url': url})
159 ie_key = 'Kaltura'
160 else:
161 PLAYER_REGEX = r'<iframe src="(?P<xml_root>.+?)/(?:gdc-)?player.*?\.html.*?".*?</iframe>'
162
163 xml_root = self._html_search_regex(
164 PLAYER_REGEX, start_page, 'xml root', default=None)
165 if xml_root is None:
166 # Probably need to authenticate
167 login_res = self._login(webpage_url, display_id)
168 if login_res is None:
169 self.report_warning('Could not login.')
170 else:
171 start_page = login_res
172 # Grab the url from the authenticated page
173 xml_root = self._html_search_regex(
174 PLAYER_REGEX, start_page, 'xml root')
175
176 xml_name = self._html_search_regex(
177 r'<iframe src=".*?\?xml(?:=|URL=xml/)(.+?\.xml).*?".*?</iframe>',
178 start_page, 'xml filename')
179 embed_url = '%s/xml/%s' % (xml_root, xml_name)
180 ie_key = 'DigitallySpeaking'
181
182 return {
183 '_type': 'url_transparent',
184 'id': video_id,
185 'display_id': display_id,
186 'url': embed_url,
187 'ie_key': ie_key,
188 }