def download_video(youtube_id, download_path="../content/", download_url=OUTSIDE_DOWNLOAD_URL, format="mp4", callback=None): """Downloads the video file to disk (note: this does NOT invalidate any of the cached html files in KA Lite)""" ensure_dir(download_path) url, thumb_url = get_outside_video_urls(youtube_id, download_url=download_url, format=format) video_filename = "%(id)s.%(format)s" % {"id": youtube_id, "format": format} filepath = download_path + video_filename thumb_filename = "%(id)s.png" % {"id": youtube_id} thumb_filepath = download_path + thumb_filename try: path, response = download_file(url, filepath, callback_percent_proxy(callback, end_percent=95)) if not response.type.startswith("video"): raise URLNotFound("Video was not found!") path, response = download_file(thumb_url, thumb_filepath, callback_percent_proxy(callback, start_percent=95, end_percent=100)) if not response.type.startswith("image"): raise URLNotFound("Thumbnail was not found!") except DownloadCancelled: delete_downloaded_files(youtube_id, download_path) raise except Exception as e: delete_downloaded_files(youtube_id, download_path) raise
def get_language_pack(lang_code, software_version, callback): """Download language pack for specified language""" lang_code = lcode_to_ietf(lang_code) logging.info("Retrieving language pack: %s" % lang_code) request_url = get_language_pack_url(lang_code, software_version) path, response = download_file(request_url, callback=callback_percent_proxy(callback)) return path
def download_video(youtube_id, download_path="../content/", download_url=OUTSIDE_DOWNLOAD_URL, format="mp4", callback=None): """Downloads the video file to disk (note: this does NOT invalidate any of the cached html files in KA Lite)""" ensure_dir(download_path) url, thumb_url = get_outside_video_urls(youtube_id, download_url=download_url, format=format) video_filename = "%(id)s.%(format)s" % {"id": youtube_id, "format": format} filepath = download_path + video_filename thumb_filename = "%(id)s.png" % {"id": youtube_id} thumb_filepath = download_path + thumb_filename try: path, response = download_file( url, filepath, callback_percent_proxy(callback, end_percent=95)) if not response.type.startswith("video"): raise URLNotFound("Video was not found!") path, response = download_file( thumb_url, thumb_filepath, callback_percent_proxy(callback, start_percent=95, end_percent=100)) if not response.type.startswith("image"): raise URLNotFound("Thumbnail was not found!") except DownloadCancelled: delete_downloaded_files(youtube_id, download_path) raise except Exception as e: delete_downloaded_files(youtube_id, download_path) raise