[skillshare:class] use brightcove extractor
This commit is contained in:
parent
45cdca687c
commit
39eb11694c
@ -2,6 +2,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import json
|
import json
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from .brightcove import BrightcoveNewIE
|
||||||
|
|
||||||
|
|
||||||
class SkillshareClassIE(InfoExtractor):
|
class SkillshareClassIE(InfoExtractor):
|
||||||
@ -10,52 +11,26 @@ class SkillshareClassIE(InfoExtractor):
|
|||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'https://www.skillshare.com/classes/SEO-Today-Strategies-to-Earn-Trust-Rank-High-and-Stand-Out/423483018',
|
'url': 'https://www.skillshare.com/classes/SEO-Today-Strategies-to-Earn-Trust-Rank-High-and-Stand-Out/423483018',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
'info_dict': {
|
|
||||||
'id': '5463396146001',
|
|
||||||
'ext': 'mp4',
|
|
||||||
'title': 'Introduction',
|
|
||||||
# TODO more properties, either as:
|
|
||||||
# * A value
|
|
||||||
# * MD5 checksum; start the string with md5:
|
|
||||||
# * A regular expression; start the string with re:
|
|
||||||
# * Any Python type (for example int or float)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
search_term = r'(?P<json_line>{"userData":{.+});\n'
|
|
||||||
lesson_info_api_url_format = "https://www.skillshare.com/sessions/{}/video"
|
|
||||||
video_api_url_format = "https://edge.api.brightcove.com/playback/v1/accounts/{}/videos/{}"
|
|
||||||
headers = {"Accept": "application/json;pk=BCpkADawqM2OOcM6njnM7hf9EaK6lIFlqiXB0iWjqGWU QjU7R8965xUvIQNqdQbnDTLz0IAO7E6Ir2rIbXJtFdzrGtitoee0n1XXRliD-RH9A-svuvNW 9qgo3Bh34HEZjXjG4Nml4iyz3KqF"}
|
|
||||||
class_id = self._match_id(url)
|
class_id = self._match_id(url)
|
||||||
class_page = self._download_webpage(url, class_id)
|
class_json_data = json.loads(self._search_regex(r'(?P<json_line>{"userData":{.+});\n', self._download_webpage(url, class_id), 'class_json_data'))
|
||||||
class_json_data = json.loads(self._search_regex(search_term, class_page, 'class_json_data'))
|
|
||||||
account_id = str(class_json_data.get('pageData').get('videoPlayerData').get('brightcoveAccountId'))
|
account_id = str(class_json_data.get('pageData').get('videoPlayerData').get('brightcoveAccountId'))
|
||||||
class_title = class_json_data.get('pageData').get('headerData').get('title')
|
|
||||||
lessons = class_json_data.get('pageData').get('videoPlayerData').get('units')[0].get('sessions')
|
lessons = class_json_data.get('pageData').get('videoPlayerData').get('units')[0].get('sessions')
|
||||||
videos = []
|
entries = []
|
||||||
for lesson in lessons:
|
for lesson in lessons:
|
||||||
lesson_id = str(lesson.get('id'))
|
lesson_id = str(lesson.get('id'))
|
||||||
lesson_info_api_url = lesson_info_api_url_format.format(lesson_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(lesson_info_api_url, lesson_id)
|
|
||||||
print(lesson_info_api_response)
|
|
||||||
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.get('video_hashed_id')[3:]
|
video_hashed_id = lesson_info_api_response.get('video_hashed_id')[3:]
|
||||||
video_api_url = video_api_url_format.format(account_id, video_hashed_id)
|
entry = {
|
||||||
video_api_response = self._download_json(video_api_url, video_hashed_id, headers=headers)
|
'_type': 'url_transparent',
|
||||||
lesson_title = lesson.get('title')
|
|
||||||
lesson_url = video_api_response.get('sources')[-1].get('src')
|
|
||||||
video = {
|
|
||||||
'id': video_hashed_id,
|
'id': video_hashed_id,
|
||||||
'title': lesson_title,
|
'title': lesson.get('title'),
|
||||||
'url': lesson_url,
|
'ie_key': BrightcoveNewIE.ie_key(),
|
||||||
'ext': 'mp4',
|
'url': 'https://players.brightcove.net/{}/default_default/index.html?videoId={}'.format(account_id, video_hashed_id),
|
||||||
}
|
}
|
||||||
videos.append(video)
|
entries.append(entry)
|
||||||
return {
|
return self.playlist_result(entries, class_id, class_json_data.get('pageData').get('headerData').get('title'), class_json_data.get("pageData").get('sectionData').get('description'))
|
||||||
'id': class_id,
|
|
||||||
'title': class_title,
|
|
||||||
'_type': 'playlist',
|
|
||||||
'entries': videos
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user