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 _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',
38 def _real_initialize(self):
42 (username, password) = self._get_login_info()
45 'Pluralsight account is required, use --username and --password options to provide account credentials.',
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 mobj = re.match(self._VALID_URL, url)
80 author = mobj.group('author')
81 name = mobj.group('name')
82 clip_id = mobj.group('clip')
83 course = mobj.group('course')
85 display_id = '%s-%s' % (name, clip_id)
87 webpage = self._download_webpage(url, display_id)
89 collection = self._parse_json(
91 r'moduleCollection\s*:\s*new\s+ModuleCollection\((\[.+?\])\s*,\s*\$rootScope\)',
95 module, clip = None, None
97 for module_ in collection:
98 if module_.get('moduleName') == name:
100 for clip_ in module_.get('clips', []):
101 clip_index = clip_.get('clipIndex')
102 if clip_index is None:
104 if compat_str(clip_index) == clip_id:
109 raise ExtractorError('Unable to resolve clip')
112 'low': {'width': 640, 'height': 480},
113 'medium': {'width': 848, 'height': 640},
114 'high': {'width': 1024, 'height': 768},
117 ALLOWED_QUALITIES = (
119 ('mp4', ('low', 'medium', 'high',)),
123 for ext, qualities in ALLOWED_QUALITIES:
124 for quality in qualities:
125 f = QUALITIES[quality].copy()
134 'q': '%dx%d' % (f['width'], f['height']),
136 request = compat_urllib_request.Request(
137 'http://www.pluralsight.com/training/Player/ViewClip',
138 json.dumps(clip_post).encode('utf-8'))
139 request.add_header('Content-Type', 'application/json;charset=utf-8')
140 format_id = '%s-%s' % (ext, quality)
141 clip_url = self._download_webpage(
142 request, display_id, 'Downloading %s URL' % format_id, fatal=False)
148 'format_id': format_id,
151 self._sort_formats(formats)
154 # http://www.pluralsight.com/training/Player/ViewClip + cap = true
156 # http://www.pluralsight.com/training/Player/Captions
157 # { a = author, cn = clip_id, lc = end, m = name }
160 'id': clip['clipName'],
161 'title': '%s - %s' % (module['title'], clip['title']),
162 'duration': int_or_none(clip.get('duration')) or parse_duration(clip.get('formattedDuration')),
168 class PluralsightCourseIE(InfoExtractor):
169 IE_NAME = 'pluralsight:course'
170 _VALID_URL = r'https?://(?:www\.)?pluralsight\.com/courses/(?P<id>[^/]+)'
172 # Free course from Pluralsight Starter Subscription for Microsoft TechNet
173 # https://offers.pluralsight.com/technet?loc=zTS3z&prod=zOTprodz&tech=zOttechz&prog=zOTprogz&type=zSOz&media=zOTmediaz&country=zUSz
174 'url': 'http://www.pluralsight.com/courses/hosting-sql-server-windows-azure-iaas',
176 'id': 'hosting-sql-server-windows-azure-iaas',
177 'title': 'Hosting SQL Server in Microsoft Azure IaaS Fundamentals',
178 'description': 'md5:61b37e60f21c4b2f91dc621a977d0986',
180 'playlist_count': 31,
183 def _real_extract(self, url):
184 course_id = self._match_id(url)
188 course = self._download_json(
189 'http://www.pluralsight.com/data/course/%s' % course_id,
190 course_id, 'Downloading course JSON')
192 title = course['title']
193 description = course.get('description') or course.get('shortDescription')
195 course_data = self._download_json(
196 'http://www.pluralsight.com/data/course/content/%s' % course_id,
197 course_id, 'Downloading course data JSON')
200 for module in course_data:
201 for clip in module.get('clips', []):
202 player_parameters = clip.get('playerParameters')
203 if not player_parameters:
205 entries.append(self.url_result(
206 'http://www.pluralsight.com/training/player?%s' % player_parameters,
209 return self.playlist_result(entries, course_id, title, description)