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