1 from __future__ import unicode_literals
5 from .common import InfoExtractor
19 class PluralsightIE(InfoExtractor):
20 IE_NAME = 'pluralsight'
21 _VALID_URL = r'https?://(?:(?:www|app)\.)?pluralsight\.com/training/player\?'
22 _LOGIN_URL = 'https://app.pluralsight.com/id/'
23 _API_BASE = 'http://app.pluralsight.com'
24 _NETRC_MACHINE = 'pluralsight'
27 'url': 'http://www.pluralsight.com/training/player?author=mike-mckeown&name=hosting-sql-server-windows-azure-iaas-m7-mgmt&mode=live&clip=3&course=hosting-sql-server-windows-azure-iaas',
28 'md5': '4d458cf5cf4c593788672419a8dd4cf8',
30 'id': 'hosting-sql-server-windows-azure-iaas-m7-mgmt-04',
32 'title': 'Management of SQL Server - Demo Monitoring',
35 'skip': 'Requires pluralsight account credentials',
37 'url': 'https://app.pluralsight.com/training/player?course=angularjs-get-started&author=scott-allen&name=angularjs-get-started-m1-introduction&clip=0&mode=live',
38 'only_matching': True,
40 # available without pluralsight account
41 'url': 'http://app.pluralsight.com/training/player?author=scott-allen&name=angularjs-get-started-m1-introduction&mode=live&clip=0&course=angularjs-get-started',
42 'only_matching': True,
45 def _real_initialize(self):
49 (username, password) = self._get_login_info()
53 login_page = self._download_webpage(
54 self._LOGIN_URL, None, 'Downloading login page')
56 login_form = self._hidden_inputs(login_page)
59 'Username': username.encode('utf-8'),
60 'Password': password.encode('utf-8'),
63 post_url = self._search_regex(
64 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
65 'post url', default=self._LOGIN_URL, group='url')
67 if not post_url.startswith('http'):
68 post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
70 request = compat_urllib_request.Request(
71 post_url, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
72 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
74 response = self._download_webpage(
75 request, None, 'Logging in as %s' % username)
77 error = self._search_regex(
78 r'<span[^>]+class="field-validation-error"[^>]*>([^<]+)</span>',
79 response, 'error message', default=None)
81 raise ExtractorError('Unable to login: %s' % error, expected=True)
83 def _real_extract(self, url):
84 qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
86 author = qs.get('author', [None])[0]
87 name = qs.get('name', [None])[0]
88 clip_id = qs.get('clip', [None])[0]
89 course = qs.get('course', [None])[0]
91 if any(not f for f in (author, name, clip_id, course,)):
92 raise ExtractorError('Invalid URL', expected=True)
94 display_id = '%s-%s' % (name, clip_id)
96 webpage = self._download_webpage(url, display_id)
98 collection = self._parse_json(
100 r'moduleCollection\s*:\s*new\s+ModuleCollection\((\[.+?\])\s*,\s*\$rootScope\)',
104 module, clip = None, None
106 for module_ in collection:
107 if module_.get('moduleName') == name:
109 for clip_ in module_.get('clips', []):
110 clip_index = clip_.get('clipIndex')
111 if clip_index is None:
113 if compat_str(clip_index) == clip_id:
118 raise ExtractorError('Unable to resolve clip')
121 'low': {'width': 640, 'height': 480},
122 'medium': {'width': 848, 'height': 640},
123 'high': {'width': 1024, 'height': 768},
126 ALLOWED_QUALITIES = (
128 ('mp4', ('low', 'medium', 'high',)),
132 for ext, qualities in ALLOWED_QUALITIES:
133 for quality in qualities:
134 f = QUALITIES[quality].copy()
143 'q': '%dx%d' % (f['width'], f['height']),
145 request = compat_urllib_request.Request(
146 '%s/training/Player/ViewClip' % self._API_BASE,
147 json.dumps(clip_post).encode('utf-8'))
148 request.add_header('Content-Type', 'application/json;charset=utf-8')
149 format_id = '%s-%s' % (ext, quality)
150 clip_url = self._download_webpage(
151 request, display_id, 'Downloading %s URL' % format_id, fatal=False)
157 'format_id': format_id,
160 self._sort_formats(formats)
163 # http://www.pluralsight.com/training/Player/ViewClip + cap = true
165 # http://www.pluralsight.com/training/Player/Captions
166 # { a = author, cn = clip_id, lc = end, m = name }
169 'id': clip['clipName'],
170 'title': '%s - %s' % (module['title'], clip['title']),
171 'duration': int_or_none(clip.get('duration')) or parse_duration(clip.get('formattedDuration')),
177 class PluralsightCourseIE(InfoExtractor):
178 IE_NAME = 'pluralsight:course'
179 _VALID_URL = r'https?://(?:(?:www|app)\.)?pluralsight\.com/(?:library/)?courses/(?P<id>[^/]+)'
181 # Free course from Pluralsight Starter Subscription for Microsoft TechNet
182 # https://offers.pluralsight.com/technet?loc=zTS3z&prod=zOTprodz&tech=zOttechz&prog=zOTprogz&type=zSOz&media=zOTmediaz&country=zUSz
183 'url': 'http://www.pluralsight.com/courses/hosting-sql-server-windows-azure-iaas',
185 'id': 'hosting-sql-server-windows-azure-iaas',
186 'title': 'Hosting SQL Server in Microsoft Azure IaaS Fundamentals',
187 'description': 'md5:61b37e60f21c4b2f91dc621a977d0986',
189 'playlist_count': 31,
191 # available without pluralsight account
192 'url': 'https://www.pluralsight.com/courses/angularjs-get-started',
193 'only_matching': True,
195 'url': 'https://app.pluralsight.com/library/courses/understanding-microsoft-azure-amazon-aws/table-of-contents',
196 'only_matching': True,
199 def _real_extract(self, url):
200 course_id = self._match_id(url)
204 course = self._download_json(
205 '%s/data/course/%s' % (self._API_BASE, course_id),
206 course_id, 'Downloading course JSON')
208 title = course['title']
209 description = course.get('description') or course.get('shortDescription')
211 course_data = self._download_json(
212 '%s/data/course/content/%s' % (self._API_BASE, course_id),
213 course_id, 'Downloading course data JSON')
216 for module in course_data:
217 for clip in module.get('clips', []):
218 player_parameters = clip.get('playerParameters')
219 if not player_parameters:
221 entries.append(self.url_result(
222 '%s/training/player?%s' % (self._API_BASE, player_parameters),
225 return self.playlist_result(entries, course_id, title, description)