]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/gdcvault.py
[dispeak] Add new extractor
[yt-dlp.git] / youtube_dl / extractor / gdcvault.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 HEADRequest,
8 sanitized_Request,
9 urlencode_postdata,
10 )
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 'url': 'http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface',
56 'md5': 'a8efb6c31ed06ca8739294960b2dbabd',
57 'info_dict': {
58 'id': '1023460',
59 'ext': 'mp4',
60 'display_id': 'Tenacious-Design-and-The-Interface',
61 'title': 'Tenacious Design and The Interface of \'Destiny\'',
62 },
63 },
64 ]
65
66 def _login(self, webpage_url, display_id):
67 (username, password) = self._get_login_info()
68 if username is None or password is None:
69 self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
70 return None
71
72 mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
73 login_url = mobj.group('root_url') + 'api/login.php'
74 logout_url = mobj.group('root_url') + 'logout'
75
76 login_form = {
77 'email': username,
78 'password': password,
79 }
80
81 request = sanitized_Request(login_url, urlencode_postdata(login_form))
82 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
83 self._download_webpage(request, display_id, 'Logging in')
84 start_page = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page')
85 self._download_webpage(logout_url, display_id, 'Logging out')
86
87 return start_page
88
89 def _real_extract(self, url):
90 mobj = re.match(self._VALID_URL, url)
91
92 video_id = mobj.group('id')
93 display_id = mobj.group('name') or video_id
94
95 webpage_url = 'http://www.gdcvault.com/play/' + video_id
96 start_page = self._download_webpage(webpage_url, display_id)
97
98 direct_url = self._search_regex(
99 r's1\.addVariable\("file",\s*encodeURIComponent\("(/[^"]+)"\)\);',
100 start_page, 'url', default=None)
101 if direct_url:
102 title = self._html_search_regex(
103 r'<td><strong>Session Name</strong></td>\s*<td>(.*?)</td>',
104 start_page, 'title')
105 video_url = 'http://www.gdcvault.com' + direct_url
106 # resolve the url so that we can detect the correct extension
107 head = self._request_webpage(HEADRequest(video_url), video_id)
108 video_url = head.geturl()
109
110 return {
111 'id': video_id,
112 'display_id': display_id,
113 'url': video_url,
114 'title': title,
115 }
116
117 PLAYER_REGEX = r'<iframe src="(?P<xml_root>.+?)/player.*?\.html.*?".*?</iframe>'
118
119 xml_root = self._html_search_regex(
120 PLAYER_REGEX, start_page, 'xml root', default=None)
121 if xml_root is None:
122 # Probably need to authenticate
123 login_res = self._login(webpage_url, display_id)
124 if login_res is None:
125 self.report_warning('Could not login.')
126 else:
127 start_page = login_res
128 # Grab the url from the authenticated page
129 xml_root = self._html_search_regex(
130 PLAYER_REGEX, start_page, 'xml root')
131
132 xml_name = self._html_search_regex(
133 r'<iframe src=".*?\?xml=(.+?\.xml).*?".*?</iframe>',
134 start_page, 'xml filename', default=None)
135 if xml_name is None:
136 # Fallback to the older format
137 xml_name = self._html_search_regex(
138 r'<iframe src=".*?\?xmlURL=xml/(?P<xml_file>.+?\.xml).*?".*?</iframe>',
139 start_page, 'xml filename')
140
141 return {
142 '_type': 'url_transparent',
143 'id': video_id,
144 'display_id': display_id,
145 'url': '%s/xml/%s' % (xml_root, xml_name),
146 'ie': 'DigitalSpeaking',
147 }