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