1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-22 16:44:32 +01:00

[linkedin:learning] extract chapter_number and chapter_id(closes #19162)

This commit is contained in:
Remita Amine 2019-02-08 07:21:31 +01:00
parent 04eacf5453
commit 91effe22a0

View File

@ -34,12 +34,15 @@ class LinkedInLearningBaseIE(InfoExtractor):
'Csrf-Token': self._get_cookies(api_url)['JSESSIONID'].value, 'Csrf-Token': self._get_cookies(api_url)['JSESSIONID'].value,
}, query=query)['elements'][0] }, query=query)['elements'][0]
def _get_video_id(self, urn, course_slug, video_slug): def _get_urn_id(self, video_data):
urn = video_data.get('urn')
if urn: if urn:
mobj = re.search(r'urn:li:lyndaCourse:\d+,(\d+)', urn) mobj = re.search(r'urn:li:lyndaCourse:\d+,(\d+)', urn)
if mobj: if mobj:
return mobj.group(1) return mobj.group(1)
return '%s/%s' % (course_slug, video_slug)
def _get_video_id(self, video_data, course_slug, video_slug):
return self._get_urn_id(video_data) or '%s/%s' % (course_slug, video_slug)
def _real_initialize(self): def _real_initialize(self):
email, password = self._get_login_info() email, password = self._get_login_info()
@ -123,7 +126,7 @@ class LinkedInLearningIE(LinkedInLearningBaseIE):
self._sort_formats(formats, ('width', 'height', 'source_preference', 'tbr', 'abr')) self._sort_formats(formats, ('width', 'height', 'source_preference', 'tbr', 'abr'))
return { return {
'id': self._get_video_id(video_data.get('urn'), course_slug, video_slug), 'id': self._get_video_id(video_data, course_slug, video_slug),
'title': title, 'title': title,
'formats': formats, 'formats': formats,
'thumbnail': video_data.get('defaultThumbnail'), 'thumbnail': video_data.get('defaultThumbnail'),
@ -154,18 +157,21 @@ class LinkedInLearningCourseIE(LinkedInLearningBaseIE):
course_data = self._call_api(course_slug, 'chapters,description,title') course_data = self._call_api(course_slug, 'chapters,description,title')
entries = [] entries = []
for chapter in course_data.get('chapters', []): for chapter_number, chapter in enumerate(course_data.get('chapters', []), 1):
chapter_title = chapter.get('title') chapter_title = chapter.get('title')
chapter_id = self._get_urn_id(chapter)
for video in chapter.get('videos', []): for video in chapter.get('videos', []):
video_slug = video.get('slug') video_slug = video.get('slug')
if not video_slug: if not video_slug:
continue continue
entries.append({ entries.append({
'_type': 'url_transparent', '_type': 'url_transparent',
'id': self._get_video_id(video.get('urn'), course_slug, video_slug), 'id': self._get_video_id(video, course_slug, video_slug),
'title': video.get('title'), 'title': video.get('title'),
'url': 'https://www.linkedin.com/learning/%s/%s' % (course_slug, video_slug), 'url': 'https://www.linkedin.com/learning/%s/%s' % (course_slug, video_slug),
'chapter': chapter_title, 'chapter': chapter_title,
'chapter_number': chapter_number,
'chapter_id': chapter_id,
'ie_key': LinkedInLearningIE.ie_key(), 'ie_key': LinkedInLearningIE.ie_key(),
}) })