1 from __future__ import unicode_literals
6 from .common import InfoExtractor
10 compat_urllib_request,
20 class PluralsightIE(InfoExtractor):
21 IE_NAME = 'pluralsight'
22 _VALID_URL = r'https?://(?:www\.)?pluralsight\.com/training/player\?author=(?P<author>[^&]+)&name=(?P<name>[^&]+)(?:&mode=live)?&clip=(?P<clip>\d+)&course=(?P<course>[^&]+)'
23 _LOGIN_URL = 'https://www.pluralsight.com/id/'
24 _ACCOUNT_CREDENTIALS_HINT = 'Use --username and --password options to provide lynda.com account credentials.'
25 _NETRC_MACHINE = 'pluralsight'
28 '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',
29 'md5': '4d458cf5cf4c593788672419a8dd4cf8',
31 'id': 'hosting-sql-server-windows-azure-iaas-m7-mgmt-04',
33 'title': 'Management of SQL Server - Demo Monitoring',
36 'skip': 'Requires pluralsight account credentials',
39 def _real_initialize(self):
43 (username, password) = self._get_login_info()
46 'Pluralsight account is required, use --username and --password options to provide account credentials.',
49 login_page = self._download_webpage(
50 self._LOGIN_URL, None, 'Downloading login page')
52 login_form = self._hidden_inputs(login_page)
55 'Username': username.encode('utf-8'),
56 'Password': password.encode('utf-8'),
59 post_url = self._search_regex(
60 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
61 'post url', default=self._LOGIN_URL, group='url')
63 if not post_url.startswith('http'):
64 post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
66 request = compat_urllib_request.Request(
67 post_url, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
68 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
70 response = self._download_webpage(
71 request, None, 'Logging in as %s' % username)
73 error = self._search_regex(
74 r'<span[^>]+class="field-validation-error"[^>]*>([^<]+)</span>',
75 response, 'error message', default=None)
77 raise ExtractorError('Unable to login: %s' % error, expected=True)
79 def _real_extract(self, url):
80 mobj = re.match(self._VALID_URL, url)
81 author = mobj.group('author')
82 name = mobj.group('name')
83 clip_id = mobj.group('clip')
84 course = mobj.group('course')
86 display_id = '%s-%s' % (name, clip_id)
88 webpage = self._download_webpage(url, display_id)
90 collection = self._parse_json(
92 r'moduleCollection\s*:\s*new\s+ModuleCollection\((\[.+?\])\s*,\s*\$rootScope\)',
96 module, clip = None, None
98 for module_ in collection:
99 if module_.get('moduleName') == name:
101 for clip_ in module_.get('clips', []):
102 clip_index = clip_.get('clipIndex')
103 if clip_index is None:
105 if compat_str(clip_index) == clip_id:
110 raise ExtractorError('Unable to resolve clip')
113 'low': {'width': 640, 'height': 480},
114 'medium': {'width': 848, 'height': 640},
115 'high': {'width': 1024, 'height': 768},
118 ALLOWED_QUALITIES = (
120 ('mp4', ('low', 'medium', 'high',)),
124 for ext, qualities in ALLOWED_QUALITIES:
125 for quality in qualities:
126 f = QUALITIES[quality].copy()
135 'q': '%dx%d' % (f['width'], f['height']),
137 request = compat_urllib_request.Request(
138 'http://www.pluralsight.com/training/Player/ViewClip',
139 json.dumps(clip_post).encode('utf-8'))
140 request.add_header('Content-Type', 'application/json;charset=utf-8')
141 format_id = '%s-%s' % (ext, quality)
142 clip_url = self._download_webpage(
143 request, display_id, 'Downloading %s URL' % format_id, fatal=False)
149 'format_id': format_id,
152 self._sort_formats(formats)
155 # http://www.pluralsight.com/training/Player/ViewClip + cap = true
157 # http://www.pluralsight.com/training/Player/Captions
158 # { a = author, cn = clip_id, lc = end, m = name }
161 'id': clip['clipName'],
162 'title': '%s - %s' % (module['title'], clip['title']),
163 'duration': int_or_none(clip.get('duration')) or parse_duration(clip.get('formattedDuration')),
169 class PluralsightCourseIE(InfoExtractor):
170 IE_NAME = 'pluralsight:course'
171 _VALID_URL = r'https?://(?:www\.)?pluralsight\.com/courses/(?P<id>[^/]+)'
173 # Free course from Pluralsight Starter Subscription for Microsoft TechNet
174 # https://offers.pluralsight.com/technet?loc=zTS3z&prod=zOTprodz&tech=zOttechz&prog=zOTprogz&type=zSOz&media=zOTmediaz&country=zUSz
175 'url': 'http://www.pluralsight.com/courses/hosting-sql-server-windows-azure-iaas',
177 'id': 'hosting-sql-server-windows-azure-iaas',
178 'title': 'Hosting SQL Server in Microsoft Azure IaaS Fundamentals',
179 'description': 'md5:61b37e60f21c4b2f91dc621a977d0986',
181 'playlist_count': 31,
184 def _real_extract(self, url):
185 course_id = self._match_id(url)
187 course = self._download_json(
188 'http://www.pluralsight.com/data/course/%s' % course_id,
189 course_id, 'Downloading course JSON')
191 title = course['title']
192 description = course.get('description') or course.get('shortDescription')
194 course_data = self._download_json(
195 'http://www.pluralsight.com/data/course/content/%s' % course_id,
196 course_id, 'Downloading course data JSON')
201 for module in course_data:
202 for clip in module.get('clips', []):
203 if clip.get('userMayViewClip') is False:
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,
214 self._downloader.report_warning(
215 'There are %d videos in this course that are not available for you. '
216 'Upgrade your account to get access to these videos.' % may_not_view)
218 return self.playlist_result(entries, course_id, title, description)