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