def download(self): # course_path = tools.join_path(self.path, self.course_name) course_path = tools.join_path(r"F:\video\MY51CTO", "学习", self.course_name) print(course_path) tools.check_or_make_dir(course_path) for lesson in self.list: lesson_id = lesson['lesson_id'] urls = self.get_lesson_m3u8(lesson_id) file_name = tools.join_path( course_path, "%s_%s.ts" % (lesson['weight'], lesson['title'])) print(file_name) if os.path.exists(file_name): continue print("download %s" % file_name) play_key = self.get_key(self.id, lesson_id) print("视频解密key: %s" % play_key) def func_decode(video_data): return decory_video.Video().decory(play_key, str(lesson_id), video_data) tools.download(file_name, urls, func_decode)
def __init__(self): self.cache_path = tools.join_path(tools.main_path(), 'cache') tools.check_or_make_dir(self.cache_path) self.path = { 'auth': tools.join_path(self.cache_path, "auth"), 'cookies': tools.join_path(self.cache_path, "cookies"), } pass
def download(self): course_path = tools.join_path(self.path, self.course_name) print course_path tools.check_or_make_dir(course_path) for lesson in self.list: urls = self.get_lesson_m3u8(lesson['lesson_id']) file_name = tools.join_path(course_path, "%s.ts" % lesson['title']) print file_name if os.path.exists(file_name): continue print "download %s" % file_name tools.download(file_name, urls)
def download(self): course_path = tools.join_path(self.path, self.course_name) print course_path tools.check_or_make_dir(course_path) for lesson in self.list: lesson_id = lesson['lesson_id'] urls = self.get_lesson_m3u8(lesson_id) file_name = tools.join_path(course_path, "%s.ts" % lesson['title']) print file_name if os.path.exists(file_name): continue print "download %s" % file_name play_key = self.get_key(self.id, lesson_id) print "视频解密key: %s" % play_key def func_decode(video_data): return decory_video.Video().decory(play_key, str(lesson_id), video_data) tools.download(file_name, urls, func_decode)
def download_m3u8(self): course_path = tools.join_path(self.path, self.course_name) print course_path for lesson in self.list: sorted = lesson['sorted'] lesson_name = "%s.%s" % (lesson['sorted'], lesson['title']) lesson_name = tools.filename_reg_check(lesson_name) lesson_path = tools.join_path(course_path, lesson_name) print lesson_path tools.check_or_make_dir(lesson_path) m3u8_file = os.path.join(lesson_path, "vedio.m3u8") if not os.path.exists(m3u8_file): m3u8_content = self.get_lesson_m3u8(lesson['lesson_id']) with open(m3u8_file, 'w') as file: file.write(m3u8_content) else: with open(m3u8_file, "r") as f: m3u8_content = f.read() key_file = os.path.join(lesson_path, "key.key") if not os.path.exists(key_file): key_content = self.get_key(lesson['lesson_id'], m3u8_content) with open(key_file, 'w') as file: file.write(key_content)