[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 datetime import datetime
|
||||
import json
|
||||
|
||||
from .common import InfoExtractor
|
||||
from ..compat import compat_str
|
||||
from ..utils import ExtractorError
|
||||
from ..utils import int_or_none
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
int_or_none,
|
||||
try_get,
|
||||
unified_timestamp
|
||||
)
|
||||
|
||||
|
||||
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]+)"
|
||||
_LOGIN_URL = "https://api.skillshare.com/login"
|
||||
@ -66,7 +69,7 @@ class SkillshareCourseIE(SkillshareBaseIE):
|
||||
class_json = self._download_json(self._CLASS_URL % class_id,
|
||||
None,
|
||||
note="Getting class details",
|
||||
errnote="Error getting class details")
|
||||
errnote="Downloading class JSON")
|
||||
|
||||
if class_json.get("enrollment_type", 0) > self._user_type:
|
||||
raise ExtractorError("This course requires a premium account and thus can't be downloaded")
|
||||
@ -79,10 +82,11 @@ class SkillshareCourseIE(SkillshareBaseIE):
|
||||
videos = []
|
||||
for lesson_json in lessons_json:
|
||||
lesson_thumbnail_urls = [
|
||||
lesson_json.get("video_thumbnail_url", ""),
|
||||
lesson_json.get("video_thumbnail_url", ""),
|
||||
lesson_json.get("image_thumbnail", "")
|
||||
lesson_json.get("video_thumbnail_url"),
|
||||
lesson_json.get("video_thumbnail_url"),
|
||||
lesson_json.get("image_thumbnail")
|
||||
]
|
||||
lesson_thumbnail_urls = filter(None, lesson_thumbnail_urls)
|
||||
lesson_thumbnails_json = []
|
||||
for lesson_thumbnail_url in lesson_thumbnail_urls:
|
||||
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)),
|
||||
"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_timestamp_dt = datetime.strptime(lesson_json.get("create_time", ""), "%Y-%m-%d %H:%M:%S")
|
||||
lesson_timestamp = int(lesson_timestamp_dt.strftime("%s"))
|
||||
except ValueError:
|
||||
lesson_timestamp = None
|
||||
lesson_categories = [class_json.get("category")]
|
||||
if lesson_categories == [None]:
|
||||
lesson_categories = None
|
||||
|
||||
videos.append({
|
||||
"id": str(lesson_json["id"]),
|
||||
"id": compat_str(lesson_json["id"]),
|
||||
"title": lesson_json.get("title"),
|
||||
"url": self._VIDEO_URL % str(lesson_json["id"]),
|
||||
"url": self._VIDEO_URL % compat_str(lesson_json["id"]),
|
||||
"ext": "mp4",
|
||||
"thumbnails": lesson_thumbnails_json,
|
||||
"uploader": class_json["_embedded"].get("teacher", {}).get("full_name"),
|
||||
"creator": class_json["_embedded"].get("teacher", {}).get("full_name"),
|
||||
"timestamp": lesson_timestamp,
|
||||
"uploader_id": str(class_json["_embedded"].get("teacher", {}).get("username", 0)),
|
||||
"categories": [class_json.get("category")],
|
||||
"chapter": lesson_json.get("_links", {}).get("unit", {}).get("title"),
|
||||
"uploader": try_get(class_json, lambda x: x["_embedded"]["teacher"]["full_name"]),
|
||||
"creator": try_get(class_json, lambda x: x["_embedded"]["teacher"]["full_name"]),
|
||||
"timestamp": unified_timestamp(lesson_json.get("create_time")),
|
||||
"uploader_id": compat_str(try_get(class_json, lambda x: x["_embedded"]["teacher"]["username"])),
|
||||
"categories": lesson_categories,
|
||||
"chapter": try_get(lesson_json, lambda x: x["_links"]["unit"]["title"]),
|
||||
"chapter_id": compat_str(lesson_json.get("unit_id"))
|
||||
})
|
||||
|
||||
return {
|
||||
"id": class_id,
|
||||
"title": class_json.get("title"),
|
||||
"uploader": class_json["_embedded"].get("teacher", {}).get("full_name"),
|
||||
"uploader_id": str(class_json["_embedded"].get("teacher", {}).get("username", 0)),
|
||||
"title": class_json["title"],
|
||||
"uploader": try_get(class_json, lambda x: x["_embedded"]["teacher"]["full_name"]),
|
||||
"uploader_id": compat_str(try_get(class_json, lambda x: x["_embedded"]["teacher"]["username"])),
|
||||
"_type": "playlist",
|
||||
"entries": videos
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user