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

Made all requested changes

This commit is contained in:
shaileshaanand 2020-03-16 13:32:26 +05:30
parent ad0a7f6480
commit cd3a7c64ea

View File

@ -2,6 +2,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor
from .brightcove import BrightcoveNewIE from .brightcove import BrightcoveNewIE
from ..utils import (
try_get,
compat_str
)
class SkillshareClassIE(InfoExtractor): class SkillshareClassIE(InfoExtractor):
@ -14,22 +18,33 @@ class SkillshareClassIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
class_id = self._match_id(url) class_id = self._match_id(url)
class_json_data = self._parse_json(self._search_regex(r'(?P<json_line>{"userData":{.+});\n', self._download_webpage(url, class_id), 'class_json_data'), class_id) class_json_data = self._parse_json(self._search_regex(
account_id = str(class_json_data['pageData']['videoPlayerData']['brightcoveAccountId']) r'(?P<json_line>{.+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'] lessons = class_json_data['pageData']['videoPlayerData']['units'][0]['sessions']
entries = [] entries = []
for lesson in lessons: for lesson in lessons:
lesson_id = str(lesson['id']) lesson_id = lesson.get('id')
lesson_info_api_response = self._download_json("https://www.skillshare.com/sessions/{}/video".format(lesson_id), lesson_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: if 'video_hashed_id' not in lesson_info_api_response:
break 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 = { entry = {
# the brightcove extractor extracts the title and id
'_type': 'url_transparent', '_type': 'url_transparent',
'id': video_hashed_id,
'title': lesson['title'],
'ie_key': BrightcoveNewIE.ie_key(), '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) 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))