def download_subtitles(couses, self): if couses is None: return if not couses.has_key('slug'): return title = couses['slug'] download_path = self.create_download_directory() course_path = self.create_course_directory(download_path, title) data_json = os.path.join(course_path, 'index.json') with open(data_json, 'wb') as out_file: json.dump(couses, out_file) for i, lesson_data in enumerate(couses['lessonData']): lesson_title = lesson_data['title'] stats_id = lesson_data['statsId'] if stats_id is None: continue path = os.path.join( course_path, str(i) + "-" + format_filename(lesson_title) + ".vtt") if not os.path.isfile(path) or os.path.getsize(path) == 0: print("Downloading subtitle of {0}/{1}".format( format_filename(lesson_title), path)) lesson_transcript_api = TRANSCRIPTS_PATH + stats_id + ".vtt" data = requests.get(lesson_transcript_api) if data is None: continue with open(path, 'wb') as local_file: local_file.writelines(data.iter_lines()) vtt_to_srt(course_path)
def __init__(self, data_dir, query): #Based on https://gist.github.com/bonzanini/af0463b927433c73784d query_fname = helper.format_filename(query) #Handle case where user doesn't want to filter if query_fname == '' : query_fname = 'all' self.outfile = "%s/stream_%s.json" % (data_dir, query_fname) print 'Stream available at : ' + self.outfile
def download_course(url, folder, videos_download, number=None): course_id, title = get_course_id_and_title(url) title = helper.format_filename(title) if number is not None: title = str(number) + ". " + title sys.stdout.write(f'{bcolors.BKGREEN} {title} {bcolors.BKENDC}\n') download_slides(course_id, os.path.join(folder, title)) if videos_download: download_videos(course_id, os.path.join(folder, title))