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