]>
Commit | Line | Data |
---|---|---|
9e68f9fd DW |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
9e68f9fd DW |
4 | |
5 | from .common import InfoExtractor | |
5c2266df | 6 | from ..compat import compat_urllib_parse |
44cae2fb | 7 | from ..utils import ( |
8 | remove_end, | |
9 | HEADRequest, | |
5c2266df | 10 | sanitized_Request, |
44cae2fb | 11 | ) |
9e68f9fd | 12 | |
5d2519e5 | 13 | |
9e68f9fd | 14 | class GDCVaultIE(InfoExtractor): |
25f7d1be | 15 | _VALID_URL = r'https?://(?:www\.)?gdcvault\.com/play/(?P<id>\d+)/(?P<name>(\w|-)+)?' |
499bfcbf | 16 | _NETRC_MACHINE = 'gdcvault' |
83cebb8b | 17 | _TESTS = [ |
83cebb8b | 18 | { |
45344855 DW |
19 | 'url': 'http://www.gdcvault.com/play/1019721/Doki-Doki-Universe-Sweet-Simple', |
20 | 'md5': '7ce8388f544c88b7ac11c7ab1b593704', | |
21 | 'info_dict': { | |
22 | 'id': '1019721', | |
c8ff6457 | 23 | 'display_id': 'Doki-Doki-Universe-Sweet-Simple', |
45344855 DW |
24 | 'ext': 'mp4', |
25 | 'title': 'Doki-Doki Universe: Sweet, Simple and Genuine (GDC Next 10)' | |
83cebb8b DW |
26 | } |
27 | }, | |
50a138d9 | 28 | { |
45344855 | 29 | 'url': 'http://www.gdcvault.com/play/1015683/Embracing-the-Dark-Art-of', |
45344855 DW |
30 | 'info_dict': { |
31 | 'id': '1015683', | |
c8ff6457 | 32 | 'display_id': 'Embracing-the-Dark-Art-of', |
45344855 DW |
33 | 'ext': 'flv', |
34 | 'title': 'Embracing the Dark Art of Mathematical Modeling in AI' | |
35 | }, | |
f604c93c PH |
36 | 'params': { |
37 | 'skip_download': True, # Requires rtmpdump | |
50a138d9 DW |
38 | } |
39 | }, | |
5d2519e5 PH |
40 | { |
41 | 'url': 'http://www.gdcvault.com/play/1015301/Thexder-Meets-Windows-95-or', | |
42 | 'md5': 'a5eb77996ef82118afbbe8e48731b98e', | |
43 | 'info_dict': { | |
44 | 'id': '1015301', | |
c8ff6457 | 45 | 'display_id': 'Thexder-Meets-Windows-95-or', |
5d2519e5 PH |
46 | 'ext': 'flv', |
47 | 'title': 'Thexder Meets Windows 95, or Writing Great Games in the Windows 95 Environment', | |
740a7fcb PH |
48 | }, |
49 | 'skip': 'Requires login', | |
25f7d1be YCH |
50 | }, |
51 | { | |
52 | 'url': 'http://gdcvault.com/play/1020791/', | |
53 | 'only_matching': True, | |
5d2519e5 | 54 | } |
83cebb8b | 55 | ] |
9e68f9fd | 56 | |
50a138d9 DW |
57 | def _parse_mp4(self, xml_description): |
58 | video_formats = [] | |
59 | mp4_video = xml_description.find('./metadata/mp4video') | |
60 | if mp4_video is None: | |
61 | return None | |
62 | ||
63 | mobj = re.match(r'(?P<root>https?://.*?/).*', mp4_video.text) | |
64 | video_root = mobj.group('root') | |
65 | formats = xml_description.findall('./metadata/MBRVideos/MBRVideo') | |
66 | for format in formats: | |
67 | mobj = re.match(r'mp4\:(?P<path>.*)', format.find('streamName').text) | |
68 | url = video_root + mobj.group('path') | |
69 | vbr = format.find('bitrate').text | |
70 | video_formats.append({ | |
71 | 'url': url, | |
72 | 'vbr': int(vbr), | |
73 | }) | |
74 | return video_formats | |
75 | ||
76 | def _parse_flv(self, xml_description): | |
44cae2fb | 77 | formats = [] |
4432db35 | 78 | akamai_url = xml_description.find('./metadata/akamaiHost').text |
44cae2fb | 79 | audios = xml_description.find('./metadata/audios') |
80 | if audios is not None: | |
81 | for audio in audios: | |
82 | formats.append({ | |
83 | 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url, | |
84 | 'play_path': remove_end(audio.get('url'), '.flv'), | |
85 | 'ext': 'flv', | |
86 | 'vcodec': 'none', | |
87 | 'format_id': audio.get('code'), | |
88 | }) | |
50a138d9 | 89 | slide_video_path = xml_description.find('./metadata/slideVideo').text |
44cae2fb | 90 | formats.append({ |
4432db35 | 91 | 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url, |
c5181ab4 S |
92 | 'play_path': remove_end(slide_video_path, '.flv'), |
93 | 'ext': 'flv', | |
f604c93c PH |
94 | 'format_note': 'slide deck video', |
95 | 'quality': -2, | |
96 | 'preference': -2, | |
97 | 'format_id': 'slides', | |
98 | }) | |
50a138d9 | 99 | speaker_video_path = xml_description.find('./metadata/speakerVideo').text |
44cae2fb | 100 | formats.append({ |
4432db35 | 101 | 'url': 'rtmp://%s/ondemand?ovpfv=1.1' % akamai_url, |
c5181ab4 S |
102 | 'play_path': remove_end(speaker_video_path, '.flv'), |
103 | 'ext': 'flv', | |
f604c93c PH |
104 | 'format_note': 'speaker video', |
105 | 'quality': -1, | |
106 | 'preference': -1, | |
107 | 'format_id': 'speaker', | |
108 | }) | |
44cae2fb | 109 | return formats |
50a138d9 | 110 | |
c8ff6457 | 111 | def _login(self, webpage_url, display_id): |
50a138d9 DW |
112 | (username, password) = self._get_login_info() |
113 | if username is None or password is None: | |
45344855 | 114 | self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.') |
50a138d9 DW |
115 | return None |
116 | ||
117 | mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url) | |
118 | login_url = mobj.group('root_url') + 'api/login.php' | |
119 | logout_url = mobj.group('root_url') + 'logout' | |
120 | ||
121 | login_form = { | |
122 | 'email': username, | |
123 | 'password': password, | |
124 | } | |
125 | ||
5c2266df | 126 | request = sanitized_Request(login_url, compat_urllib_parse.urlencode(login_form)) |
50a138d9 | 127 | request.add_header('Content-Type', 'application/x-www-form-urlencoded') |
c8ff6457 YCH |
128 | self._download_webpage(request, display_id, 'Logging in') |
129 | start_page = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page') | |
130 | self._download_webpage(logout_url, display_id, 'Logging out') | |
50a138d9 DW |
131 | |
132 | return start_page | |
133 | ||
9e68f9fd DW |
134 | def _real_extract(self, url): |
135 | mobj = re.match(self._VALID_URL, url) | |
136 | ||
137 | video_id = mobj.group('id') | |
c8ff6457 YCH |
138 | display_id = mobj.group('name') or video_id |
139 | ||
9e68f9fd | 140 | webpage_url = 'http://www.gdcvault.com/play/' + video_id |
c8ff6457 | 141 | start_page = self._download_webpage(webpage_url, display_id) |
9e68f9fd | 142 | |
5d2519e5 PH |
143 | direct_url = self._search_regex( |
144 | r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);', | |
145 | start_page, 'url', default=None) | |
146 | if direct_url: | |
5d2519e5 PH |
147 | title = self._html_search_regex( |
148 | r'<td><strong>Session Name</strong></td>\s*<td>(.*?)</td>', | |
149 | start_page, 'title') | |
44cae2fb | 150 | video_url = 'http://www.gdcvault.com' + direct_url |
151 | # resolve the url so that we can detect the correct extension | |
152 | head = self._request_webpage(HEADRequest(video_url), video_id) | |
153 | video_url = head.geturl() | |
5d2519e5 PH |
154 | |
155 | return { | |
156 | 'id': video_id, | |
c8ff6457 | 157 | 'display_id': display_id, |
5d2519e5 | 158 | 'url': video_url, |
5d2519e5 PH |
159 | 'title': title, |
160 | } | |
50a138d9 | 161 | |
5d2519e5 PH |
162 | xml_root = self._html_search_regex( |
163 | r'<iframe src="(?P<xml_root>.*?)player.html.*?".*?</iframe>', | |
164 | start_page, 'xml root', default=None) | |
50a138d9 DW |
165 | if xml_root is None: |
166 | # Probably need to authenticate | |
c8ff6457 | 167 | login_res = self._login(webpage_url, display_id) |
5d2519e5 | 168 | if login_res is None: |
45344855 | 169 | self.report_warning('Could not login.') |
50a138d9 | 170 | else: |
5d2519e5 | 171 | start_page = login_res |
50a138d9 | 172 | # Grab the url from the authenticated page |
5d2519e5 PH |
173 | xml_root = self._html_search_regex( |
174 | r'<iframe src="(.*?)player.html.*?".*?</iframe>', | |
175 | start_page, 'xml root') | |
9e68f9fd | 176 | |
5d2519e5 PH |
177 | xml_name = self._html_search_regex( |
178 | r'<iframe src=".*?\?xml=(.+?\.xml).*?".*?</iframe>', | |
179 | start_page, 'xml filename', default=None) | |
83cebb8b DW |
180 | if xml_name is None: |
181 | # Fallback to the older format | |
182 | xml_name = self._html_search_regex(r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>', start_page, 'xml filename') | |
183 | ||
525a87f5 JMF |
184 | xml_description_url = xml_root + 'xml/' + xml_name |
185 | xml_description = self._download_xml(xml_description_url, display_id) | |
9e68f9fd DW |
186 | |
187 | video_title = xml_description.find('./metadata/title').text | |
50a138d9 DW |
188 | video_formats = self._parse_mp4(xml_description) |
189 | if video_formats is None: | |
190 | video_formats = self._parse_flv(xml_description) | |
9e68f9fd | 191 | |
45344855 | 192 | return { |
9e68f9fd | 193 | 'id': video_id, |
c8ff6457 | 194 | 'display_id': display_id, |
9e68f9fd | 195 | 'title': video_title, |
83cebb8b | 196 | 'formats': video_formats, |
45344855 | 197 | } |