[skillshare:course] Made most fixes
Fixed all noted issued except cookie authentication (desktop and mobile don't correlate) and base class (to allow more functionality to be added in the future).
This commit is contained in:
parent
58f21537bf
commit
c90aa852c2
@ -1,16 +1,19 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_str
|
from ..compat import compat_str
|
||||||
from ..utils import ExtractorError
|
from ..utils import (
|
||||||
from ..utils import int_or_none
|
ExtractorError,
|
||||||
|
int_or_none,
|
||||||
|
try_get,
|
||||||
|
unified_timestamp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SkillshareBaseIE(InfoExtractor):
|
class SkillshareBaseIE(InfoExtractor):
|
||||||
_NETRC_MACHINE = 'udemy'
|
_NETRC_MACHINE = "skillshare"
|
||||||
|
|
||||||
_TN_RE = r"uploads/video/thumbnails/[0-9a-f]+/(?P<width>[0-9]+)-(?P<height>[0-9]+)"
|
_TN_RE = r"uploads/video/thumbnails/[0-9a-f]+/(?P<width>[0-9]+)-(?P<height>[0-9]+)"
|
||||||
_LOGIN_URL = "https://api.skillshare.com/login"
|
_LOGIN_URL = "https://api.skillshare.com/login"
|
||||||
@ -66,7 +69,7 @@ class SkillshareCourseIE(SkillshareBaseIE):
|
|||||||
class_json = self._download_json(self._CLASS_URL % class_id,
|
class_json = self._download_json(self._CLASS_URL % class_id,
|
||||||
None,
|
None,
|
||||||
note="Getting class details",
|
note="Getting class details",
|
||||||
errnote="Error getting class details")
|
errnote="Downloading class JSON")
|
||||||
|
|
||||||
if class_json.get("enrollment_type", 0) > self._user_type:
|
if class_json.get("enrollment_type", 0) > self._user_type:
|
||||||
raise ExtractorError("This course requires a premium account and thus can't be downloaded")
|
raise ExtractorError("This course requires a premium account and thus can't be downloaded")
|
||||||
@ -79,10 +82,11 @@ class SkillshareCourseIE(SkillshareBaseIE):
|
|||||||
videos = []
|
videos = []
|
||||||
for lesson_json in lessons_json:
|
for lesson_json in lessons_json:
|
||||||
lesson_thumbnail_urls = [
|
lesson_thumbnail_urls = [
|
||||||
lesson_json.get("video_thumbnail_url", ""),
|
lesson_json.get("video_thumbnail_url"),
|
||||||
lesson_json.get("video_thumbnail_url", ""),
|
lesson_json.get("video_thumbnail_url"),
|
||||||
lesson_json.get("image_thumbnail", "")
|
lesson_json.get("image_thumbnail")
|
||||||
]
|
]
|
||||||
|
lesson_thumbnail_urls = filter(None, lesson_thumbnail_urls)
|
||||||
lesson_thumbnails_json = []
|
lesson_thumbnails_json = []
|
||||||
for lesson_thumbnail_url in lesson_thumbnail_urls:
|
for lesson_thumbnail_url in lesson_thumbnail_urls:
|
||||||
lesson_thumbnails_json.append({
|
lesson_thumbnails_json.append({
|
||||||
@ -90,33 +94,33 @@ class SkillshareCourseIE(SkillshareBaseIE):
|
|||||||
"width": int_or_none(self._search_regex(self._TN_RE, lesson_thumbnail_url, "width", fatal=False)),
|
"width": int_or_none(self._search_regex(self._TN_RE, lesson_thumbnail_url, "width", fatal=False)),
|
||||||
"height": int_or_none(self._search_regex(self._TN_RE, lesson_thumbnail_url, "height", fatal=False)),
|
"height": int_or_none(self._search_regex(self._TN_RE, lesson_thumbnail_url, "height", fatal=False)),
|
||||||
})
|
})
|
||||||
|
if not lesson_thumbnails_json:
|
||||||
|
lesson_thumbnails_json = None
|
||||||
|
|
||||||
try:
|
lesson_categories = [class_json.get("category")]
|
||||||
lesson_timestamp_dt = datetime.strptime(lesson_json.get("create_time", ""), "%Y-%m-%d %H:%M:%S")
|
if lesson_categories == [None]:
|
||||||
lesson_timestamp = int(lesson_timestamp_dt.strftime("%s"))
|
lesson_categories = None
|
||||||
except ValueError:
|
|
||||||
lesson_timestamp = None
|
|
||||||
|
|
||||||
videos.append({
|
videos.append({
|
||||||
"id": str(lesson_json["id"]),
|
"id": compat_str(lesson_json["id"]),
|
||||||
"title": lesson_json.get("title"),
|
"title": lesson_json.get("title"),
|
||||||
"url": self._VIDEO_URL % str(lesson_json["id"]),
|
"url": self._VIDEO_URL % compat_str(lesson_json["id"]),
|
||||||
"ext": "mp4",
|
"ext": "mp4",
|
||||||
"thumbnails": lesson_thumbnails_json,
|
"thumbnails": lesson_thumbnails_json,
|
||||||
"uploader": class_json["_embedded"].get("teacher", {}).get("full_name"),
|
"uploader": try_get(class_json, lambda x: x["_embedded"]["teacher"]["full_name"]),
|
||||||
"creator": class_json["_embedded"].get("teacher", {}).get("full_name"),
|
"creator": try_get(class_json, lambda x: x["_embedded"]["teacher"]["full_name"]),
|
||||||
"timestamp": lesson_timestamp,
|
"timestamp": unified_timestamp(lesson_json.get("create_time")),
|
||||||
"uploader_id": str(class_json["_embedded"].get("teacher", {}).get("username", 0)),
|
"uploader_id": compat_str(try_get(class_json, lambda x: x["_embedded"]["teacher"]["username"])),
|
||||||
"categories": [class_json.get("category")],
|
"categories": lesson_categories,
|
||||||
"chapter": lesson_json.get("_links", {}).get("unit", {}).get("title"),
|
"chapter": try_get(lesson_json, lambda x: x["_links"]["unit"]["title"]),
|
||||||
"chapter_id": compat_str(lesson_json.get("unit_id"))
|
"chapter_id": compat_str(lesson_json.get("unit_id"))
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"id": class_id,
|
"id": class_id,
|
||||||
"title": class_json.get("title"),
|
"title": class_json["title"],
|
||||||
"uploader": class_json["_embedded"].get("teacher", {}).get("full_name"),
|
"uploader": try_get(class_json, lambda x: x["_embedded"]["teacher"]["full_name"]),
|
||||||
"uploader_id": str(class_json["_embedded"].get("teacher", {}).get("username", 0)),
|
"uploader_id": compat_str(try_get(class_json, lambda x: x["_embedded"]["teacher"]["username"])),
|
||||||
"_type": "playlist",
|
"_type": "playlist",
|
||||||
"entries": videos
|
"entries": videos
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user