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://www.pluralsight.com/id/'
23 _NETRC_MACHINE = 'pluralsight'
26 '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',
27 'md5': '4d458cf5cf4c593788672419a8dd4cf8',
29 'id': 'hosting-sql-server-windows-azure-iaas-m7-mgmt-04',
31 'title': 'Management of SQL Server - Demo Monitoring',
34 'skip': 'Requires pluralsight account credentials',
36 'url': 'https://app.pluralsight.com/training/player?course=angularjs-get-started&author=scott-allen&name=angularjs-get-started-m1-introduction&clip=0&mode=live',
37 'only_matching': True,
40 def _real_initialize(self):
44 (username, password) = self._get_login_info()
46 self.raise_login_required('Pluralsight account is required')
48 login_page = self._download_webpage(
49 self._LOGIN_URL, None, 'Downloading login page')
51 login_form = self._hidden_inputs(login_page)
54 'Username': username.encode('utf-8'),
55 'Password': password.encode('utf-8'),
58 post_url = self._search_regex(
59 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
60 'post url', default=self._LOGIN_URL, group='url')
62 if not post_url.startswith('http'):
63 post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
65 request = compat_urllib_request.Request(
66 post_url, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
67 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
69 response = self._download_webpage(
70 request, None, 'Logging in as %s' % username)
72 error = self._search_regex(
73 r'<span[^>]+class="field-validation-error"[^>]*>([^<]+)</span>',
74 response, 'error message', default=None)
76 raise ExtractorError('Unable to login: %s' % error, expected=True)
78 def _real_extract(self, url):
79 qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
81 author = qs.get('author', [None])[0]
82 name = qs.get('name', [None])[0]
83 clip_id = qs.get('clip', [None])[0]
84 course = qs.get('course', [None])[0]
86 if any(not f for f in (author, name, clip_id, course,)):
87 raise ExtractorError('Invalid URL', expected=True)
89 display_id = '%s-%s' % (name, clip_id)
91 webpage = self._download_webpage(url, display_id)
93 collection = self._parse_json(
95 r'moduleCollection\s*:\s*new\s+ModuleCollection\((\[.+?\])\s*,\s*\$rootScope\)',
99 module, clip = None, None
101 for module_ in collection:
102 if module_.get('moduleName') == name:
104 for clip_ in module_.get('clips', []):
105 clip_index = clip_.get('clipIndex')
106 if clip_index is None:
108 if compat_str(clip_index) == clip_id:
113 raise ExtractorError('Unable to resolve clip')
116 'low': {'width': 640, 'height': 480},
117 'medium': {'width': 848, 'height': 640},
118 'high': {'width': 1024, 'height': 768},
121 ALLOWED_QUALITIES = (
123 ('mp4', ('low', 'medium', 'high',)),
127 for ext, qualities in ALLOWED_QUALITIES:
128 for quality in qualities:
129 f = QUALITIES[quality].copy()
138 'q': '%dx%d' % (f['width'], f['height']),
140 request = compat_urllib_request.Request(
141 'http://app.pluralsight.com/training/Player/ViewClip',
142 json.dumps(clip_post).encode('utf-8'))
143 request.add_header('Content-Type', 'application/json;charset=utf-8')
144 format_id = '%s-%s' % (ext, quality)
145 clip_url = self._download_webpage(
146 request, display_id, 'Downloading %s URL' % format_id, fatal=False)
152 'format_id': format_id,
155 self._sort_formats(formats)
158 # http://www.pluralsight.com/training/Player/ViewClip + cap = true
160 # http://www.pluralsight.com/training/Player/Captions
161 # { a = author, cn = clip_id, lc = end, m = name }
164 'id': clip['clipName'],
165 'title': '%s - %s' % (module['title'], clip['title']),
166 'duration': int_or_none(clip.get('duration')) or parse_duration(clip.get('formattedDuration')),
172 class PluralsightCourseIE(InfoExtractor):
173 IE_NAME = 'pluralsight:course'
174 _VALID_URL = r'https?://(?:www\.)?pluralsight\.com/courses/(?P<id>[^/]+)'
176 # Free course from Pluralsight Starter Subscription for Microsoft TechNet
177 # https://offers.pluralsight.com/technet?loc=zTS3z&prod=zOTprodz&tech=zOttechz&prog=zOTprogz&type=zSOz&media=zOTmediaz&country=zUSz
178 'url': 'http://www.pluralsight.com/courses/hosting-sql-server-windows-azure-iaas',
180 'id': 'hosting-sql-server-windows-azure-iaas',
181 'title': 'Hosting SQL Server in Microsoft Azure IaaS Fundamentals',
182 'description': 'md5:61b37e60f21c4b2f91dc621a977d0986',
184 'playlist_count': 31,
187 def _real_extract(self, url):
188 course_id = self._match_id(url)
192 course = self._download_json(
193 'http://www.pluralsight.com/data/course/%s' % course_id,
194 course_id, 'Downloading course JSON')
196 title = course['title']
197 description = course.get('description') or course.get('shortDescription')
199 course_data = self._download_json(
200 'http://www.pluralsight.com/data/course/content/%s' % course_id,
201 course_id, 'Downloading course data JSON')
204 for module in course_data:
205 for clip in module.get('clips', []):
206 player_parameters = clip.get('playerParameters')
207 if not player_parameters:
209 entries.append(self.url_result(
210 'http://www.pluralsight.com/training/player?%s' % player_parameters,
213 return self.playlist_result(entries, course_id, title, description)