Created
July 3, 2017 09:21
-
-
Save candyan/a2e310b47eefd1f968dbc9f46d95602e to your computer and use it in GitHub Desktop.
HD Course
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf8 | |
import requests | |
class HDCourse: | |
def __init__(self, id, title, teacher_name, videos): | |
self.id = id | |
self.title = title | |
self.teacher_name = teacher_name | |
self.videos = videos | |
def __repr__(self): | |
desc = u"%s (%s) %s 个视频" % \ | |
(self.title, self.teacher_name, len(self.videos)) | |
return desc.encode('utf8') | |
def download_videos(self): | |
for video in self.videos: | |
vid = video['video_id'] | |
video_title = video['title'] | |
uri = "https://course.hundun.cn/oss_video_url?app_role=yxs" \ | |
"&clarity=0&clientType=iPhone%206%20Plus_iOS_10.0.2" \ | |
"&device_type=phone&isVerify=0&net=wifi&" \ | |
"versionName=1.11.6&video_id=%s" % vid | |
res = requests.get(uri).json() | |
play_uri = res['video_info']['url'] | |
print('=' * 20) | |
print('start download %s' % video_title) | |
r = requests.get(play_uri) | |
with open(("%s.mp4" % video_title), "wb") as code: | |
code.write(r.content) | |
@classmethod | |
def get_by_id(cls, cid): | |
uri = "https://course.hundun.cn/get_course_detail?app_role=yxs" \ | |
"&clientType=iPhone%206%20Plus_iOS_10.0.2&course_id=%s" \ | |
"&device_type=phone&isVerify=0&list_type=&net=wifi&unionid=" \ | |
"&versionName=1.11.6" % cid | |
res = requests.get(uri).json() | |
course_detail = res['course_detail'] | |
course_meta = course_detail['course_meta'] | |
videos = course_detail['i18n_directory'][0]['directory'] | |
return cls(cid, | |
course_meta['title'], | |
course_meta['teacher_name'], | |
videos) | |
@classmethod | |
def get_courses(cls, page=0): | |
uri = "https://course.hundun.cn/get_course_list?app_role=yxs" \ | |
"&card_id=card_main&clientType=iPhone%206%20Plus_iOS_10.0.2" \ | |
"&device_type=phone&isVerify=0&net=wifi&order_type=time" \ | |
"&page=%s&versionName=1.11.6" % page | |
res = requests.get(uri).json() | |
return [cls.get_by_id(cr['course_id']) for cr in res['course_list']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment