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