From e258e54e5a66da89a31c6ace54fbae59ea3e248a Mon Sep 17 00:00:00 2001 From: rootyElf Date: Mon, 23 Apr 2018 19:30:14 +0200 Subject: [PATCH 1/3] Update Lynda.com extractor Add release date, author and skill level variables which can be used for the output template. --- youtube_dl/extractor/lynda.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/lynda.py b/youtube_dl/extractor/lynda.py index f5c7abc13..86c9d882a 100644 --- a/youtube_dl/extractor/lynda.py +++ b/youtube_dl/extractor/lynda.py @@ -308,6 +308,26 @@ class LyndaCourseIE(LyndaBaseIE): unaccessible_videos = 0 entries = [] + + templateVars = {} + date = course.get('DateReleasedUtc') + if date: + date = date[6:10] + '-' + date[0:2] + '-' + date[3:5] + templateVars.update({'release_date': date}) + + authors = course.get("Authors") + if authors: + authorString = '' + for author in authors: + authorString += author.get("Fullname") + ", " + authorString = authorString[:-2] + templateVars.update({'creator': authorString}) + + tags = course.get('Tags') + if tags: + for tag in tags: + if tag.get('TypeName') == 'Level': + templateVars.update({'skill_level': tag.get('Name')}) # Might want to extract videos right here from video['Formats'] as it seems 'Formats' is not provided # by single video API anymore @@ -319,14 +339,16 @@ class LyndaCourseIE(LyndaBaseIE): continue video_id = video.get('ID') if video_id: - entries.append({ + entry = { '_type': 'url_transparent', 'url': item_template % video_id, 'ie_key': LyndaIE.ie_key(), 'chapter': chapter.get('Title'), 'chapter_number': int_or_none(chapter.get('ChapterIndex')), 'chapter_id': compat_str(chapter.get('ID')), - }) + } + entry.update(templateVars) + entries.append(entry) if unaccessible_videos > 0: self._downloader.report_warning( From 3afa09c0b8e290d6e7a1f84e60e177bf7d3fd912 Mon Sep 17 00:00:00 2001 From: rootyElf Date: Mon, 23 Apr 2018 19:35:40 +0200 Subject: [PATCH 2/3] Update lynda.py --- youtube_dl/extractor/lynda.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/extractor/lynda.py b/youtube_dl/extractor/lynda.py index 86c9d882a..100985710 100644 --- a/youtube_dl/extractor/lynda.py +++ b/youtube_dl/extractor/lynda.py @@ -312,7 +312,7 @@ class LyndaCourseIE(LyndaBaseIE): templateVars = {} date = course.get('DateReleasedUtc') if date: - date = date[6:10] + '-' + date[0:2] + '-' + date[3:5] + date = date[6:10] + date[0:2] + date[3:5] templateVars.update({'release_date': date}) authors = course.get("Authors") From 89ca9f8f6777f96f1ca4d71c2a79b59b2352fcdc Mon Sep 17 00:00:00 2001 From: Rooty Date: Thu, 14 Jun 2018 17:35:04 +0100 Subject: [PATCH 3/3] Removed undocumented variable "skill_level" and added checks to prevent wrong input data from crashing the program. --- youtube_dl/extractor/lynda.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/youtube_dl/extractor/lynda.py b/youtube_dl/extractor/lynda.py index 100985710..c4eef723d 100644 --- a/youtube_dl/extractor/lynda.py +++ b/youtube_dl/extractor/lynda.py @@ -309,26 +309,22 @@ class LyndaCourseIE(LyndaBaseIE): unaccessible_videos = 0 entries = [] - templateVars = {} + template_vars = {} date = course.get('DateReleasedUtc') - if date: + if isinstance(date, str) and len(date) > 10: date = date[6:10] + date[0:2] + date[3:5] - templateVars.update({'release_date': date}) + template_vars.update({'release_date': date}) authors = course.get("Authors") - if authors: - authorString = '' + if authors and isinstance(authors, list): + author_string = '' for author in authors: - authorString += author.get("Fullname") + ", " - authorString = authorString[:-2] - templateVars.update({'creator': authorString}) - - tags = course.get('Tags') - if tags: - for tag in tags: - if tag.get('TypeName') == 'Level': - templateVars.update({'skill_level': tag.get('Name')}) - + if isinstance(author, dict): + name = author.get("Fullname") + if isinstance(name, str) and name: + author_string += name + ", " + author_string = author_string[:-2] + template_vars.update({'creator': author_string}) # Might want to extract videos right here from video['Formats'] as it seems 'Formats' is not provided # by single video API anymore @@ -347,7 +343,7 @@ class LyndaCourseIE(LyndaBaseIE): 'chapter_number': int_or_none(chapter.get('ChapterIndex')), 'chapter_id': compat_str(chapter.get('ID')), } - entry.update(templateVars) + entry.update(template_vars) entries.append(entry) if unaccessible_videos > 0: