]> jfr.im git - yt-dlp.git/blob - youtube_dlc/extractor/gdcvault.py
Merge pull request #187 from pukkandan/break-on-existing
[yt-dlp.git] / youtube_dlc / extractor / gdcvault.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from .kaltura import KalturaIE
7 from ..utils import (
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': '201311826596_AWNY',
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': '201203272_1330951438328RSXR',
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 # Hard-coded hostname
56 'url': 'http://gdcvault.com/play/1023460/Tenacious-Design-and-The-Interface',
57 'md5': 'a8efb6c31ed06ca8739294960b2dbabd',
58 'info_dict': {
59 'id': '840376_BQRC',
60 'ext': 'mp4',
61 'display_id': 'Tenacious-Design-and-The-Interface',
62 'title': 'Tenacious Design and The Interface of \'Destiny\'',
63 },
64 },
65 {
66 # Multiple audios
67 'url': 'http://www.gdcvault.com/play/1014631/Classic-Game-Postmortem-PAC',
68 'info_dict': {
69 'id': '12396_1299111843500GMPX',
70 'ext': 'mp4',
71 'title': 'How to Create a Good Game - From My Experience of Designing Pac-Man',
72 },
73 # 'params': {
74 # 'skip_download': True, # Requires rtmpdump
75 # 'format': 'jp', # The japanese audio
76 # }
77 },
78 {
79 # gdc-player.html
80 'url': 'http://www.gdcvault.com/play/1435/An-American-engine-in-Tokyo',
81 'info_dict': {
82 'id': '9350_1238021887562UHXB',
83 'display_id': 'An-American-engine-in-Tokyo',
84 'ext': 'mp4',
85 'title': 'An American Engine in Tokyo:/nThe collaboration of Epic Games and Square Enix/nFor THE LAST REMINANT',
86 },
87 },
88 {
89 # Kaltura Embed
90 'url': 'https://www.gdcvault.com/play/1026180/Mastering-the-Apex-of-Scaling',
91 'info_dict': {
92 'id': '0_h1fg8j3p',
93 'ext': 'mp4',
94 'title': 'Mastering the Apex of Scaling Game Servers (Presented by Multiplay)',
95 'timestamp': 1554401811,
96 'upload_date': '20190404',
97 'uploader_id': 'joe@blazestreaming.com',
98 },
99 'params': {
100 'format': 'mp4-408',
101 },
102 },
103 ]
104
105 def _login(self, webpage_url, display_id):
106 username, password = self._get_login_info()
107 if username is None or password is None:
108 self.report_warning('It looks like ' + webpage_url + ' requires a login. Try specifying a username and password and try again.')
109 return None
110
111 mobj = re.match(r'(?P<root_url>https?://.*?/).*', webpage_url)
112 login_url = mobj.group('root_url') + 'api/login.php'
113 logout_url = mobj.group('root_url') + 'logout'
114
115 login_form = {
116 'email': username,
117 'password': password,
118 }
119
120 request = sanitized_Request(login_url, urlencode_postdata(login_form))
121 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
122 self._download_webpage(request, display_id, 'Logging in')
123 webpage = self._download_webpage(webpage_url, display_id, 'Getting authenticated video page')
124 self._download_webpage(logout_url, display_id, 'Logging out')
125
126 return webpage
127
128 def _real_extract(self, url):
129 video_id, name = re.match(self._VALID_URL, url).groups()
130 display_id = name or video_id
131
132 webpage = self._download_webpage(url, display_id)
133
134 title = self._html_search_regex(
135 r'<td><strong>Session Name:?</strong></td>\s*<td>(.*?)</td>',
136 webpage, 'title')
137
138 PLAYER_REGEX = r'<iframe src=\"(?P<manifest_url>.*?)\".*?</iframe>'
139 manifest_url = self._html_search_regex(
140 PLAYER_REGEX, webpage, 'manifest_url')
141
142 partner_id = self._search_regex(
143 r'/p(?:artner_id)?/(\d+)', manifest_url, 'partner id',
144 default='1670711')
145
146 kaltura_id = self._search_regex(
147 r'entry_id=(?P<id>(?:[^&])+)', manifest_url,
148 'kaltura id', group='id')
149
150 return {
151 '_type': 'url_transparent',
152 'url': 'kaltura:%s:%s' % (partner_id, kaltura_id),
153 'ie_key': KalturaIE.ie_key(),
154 'id': video_id,
155 'display_id': display_id,
156 'title': title,
157 }