diff --git a/youtube_dl/extractor/skillshare.py b/youtube_dl/extractor/skillshare.py index c787fe750..44d8680fb 100644 --- a/youtube_dl/extractor/skillshare.py +++ b/youtube_dl/extractor/skillshare.py @@ -2,6 +2,10 @@ from __future__ import unicode_literals from .common import InfoExtractor from .brightcove import BrightcoveNewIE +from ..utils import ( + try_get, + compat_str +) class SkillshareClassIE(InfoExtractor): @@ -14,22 +18,33 @@ class SkillshareClassIE(InfoExtractor): def _real_extract(self, url): class_id = self._match_id(url) - class_json_data = self._parse_json(self._search_regex(r'(?P{"userData":{.+});\n', self._download_webpage(url, class_id), 'class_json_data'), class_id) - account_id = str(class_json_data['pageData']['videoPlayerData']['brightcoveAccountId']) + class_json_data = self._parse_json(self._search_regex( + r'(?P{.+pageData.+});\n', + self._download_webpage(url, class_id), 'class_json_data'), class_id) + account_id = class_json_data['pageData']['videoPlayerData']['brightcoveAccountId'] lessons = class_json_data['pageData']['videoPlayerData']['units'][0]['sessions'] entries = [] for lesson in lessons: - lesson_id = str(lesson['id']) - lesson_info_api_response = self._download_json("https://www.skillshare.com/sessions/{}/video".format(lesson_id), lesson_id) + lesson_id = lesson.get('id') + lesson_info_api_response = self._download_json( + "https://www.skillshare.com/sessions/%s/video" % lesson_id, + lesson_id) if 'video_hashed_id' not in lesson_info_api_response: break - video_hashed_id = lesson_info_api_response['video_hashed_id'][3:] + video_hashed_id = self._search_regex( + r'(\d+)', lesson_info_api_response.get('video_hashed_id'), + 'video_hashed_id') entry = { + # the brightcove extractor extracts the title and id '_type': 'url_transparent', - 'id': video_hashed_id, - 'title': lesson['title'], 'ie_key': BrightcoveNewIE.ie_key(), - 'url': 'https://players.brightcove.net/{}/default_default/index.html?videoId={}'.format(account_id, video_hashed_id), + 'url': 'https://players.brightcove.net/%s/default_default/index.html?videoId=%s' % (account_id, video_hashed_id), } entries.append(entry) - return self.playlist_result(entries, class_id, class_json_data['pageData']['headerData']['title'], class_json_data.get("pageData").get('sectionData').get('description')) + return self.playlist_result( + entries, class_id, try_get( + class_json_data, lambda x: x['pageData']['headerData']['title'], + compat_str), + try_get( + class_json_data, lambda x: x['pageData']['sectionData']['description'], + compat_str))