# coding: utf-8 from __future__ import unicode_literals import re from .common import InfoExtractor from ..utils import ( ExtractorError, float_or_none, int_or_none, urlencode_postdata, ) class LinkedInLearningBaseIE(InfoExtractor): _NETRC_MACHINE = 'linkedin' def _call_api(self, course_slug, fields, video_slug=None, resolution=None): query = { 'courseSlug': course_slug, 'fields': fields, 'q': 'slugs', } sub = '' if video_slug: query.update({ 'videoSlug': video_slug, 'resolution': '_%s' % resolution, }) sub = ' %dp' % resolution api_url = 'https://www.linkedin.com/learning-api/detailedCourses' return self._download_json( api_url, video_slug, 'Downloading%s JSON metadata' % sub, headers={ 'Csrf-Token': self._get_cookies(api_url)['JSESSIONID'].value, }, query=query)['elements'][0] def _get_video_id(self, urn, course_slug, video_slug): if urn: mobj = re.search(r'urn:li:lyndaCourse:\d+,(\d+)', urn) if mobj: return mobj.group(1) return '%s/%s' % (course_slug, video_slug) def _real_initialize(self): email, password = self._get_login_info() if email is None: return login_page = self._download_webpage( 'https://www.linkedin.com/uas/login?trk=learning', None, 'Downloading login page') action_url = self._search_regex( r'