This commit is contained in:
Puyodead1 2021-05-19 08:08:57 -04:00
parent 1da1136978
commit f9acb2918a
2 changed files with 7 additions and 6 deletions

10
main.py
View File

@ -64,7 +64,7 @@ def download_media(filename,url,lecture_working_dir,epoch = 0):
print("Segment already downloaded.. skipping write to disk..") print("Segment already downloaded.. skipping write to disk..")
else: else:
try: try:
pbar = tqdm(total=media_length, initial=0,unit='MB', unit_scale=True, desc=filename) pbar = tqdm(total=media_length, initial=0,unit='B', unit_scale=True, desc=filename)
with open(f"{lecture_working_dir}\\{filename}", 'wb') as video_file: with open(f"{lecture_working_dir}\\{filename}", 'wb') as video_file:
for chunk in media.iter_content(chunk_size=1024): for chunk in media.iter_content(chunk_size=1024):
if chunk: if chunk:
@ -221,7 +221,7 @@ def download(url, path, filename):
header = {"Range": "bytes=%s-%s" % (first_byte, file_size)} header = {"Range": "bytes=%s-%s" % (first_byte, file_size)}
pbar = tqdm( pbar = tqdm(
total=file_size, initial=first_byte, total=file_size, initial=first_byte,
unit='MB', unit_scale=True, desc=filename) unit='B', unit_scale=True, desc=filename)
req = requests.get(url, headers=header, stream=True) req = requests.get(url, headers=header, stream=True)
with(open(path, 'ab')) as f: with(open(path, 'ab')) as f:
for chunk in req.iter_content(chunk_size=1024): for chunk in req.iter_content(chunk_size=1024):
@ -256,10 +256,10 @@ def parse(data):
if not os.path.isfile(lecture_path): if not os.path.isfile(lecture_path):
download(lecture_url, lecture_path, lecture_title) download(lecture_url, lecture_path, lecture_title)
else: else:
print("Lecture " + lecture_title + " is already downloaded, skipping...") print(f"> Lecture '%s' is already downloaded, skipping..." % lecture_title)
else: else:
# encrypted # encrypted
print(f"Lecture %s has DRM, attempting to download" % lecture_title) print(f"> Lecture '%s' has DRM, attempting to download" % lecture_title)
lecture_working_dir = "%s\%s" % (working_dir, lecture_asset["id"]) # set the folder to download ephemeral files lecture_working_dir = "%s\%s" % (working_dir, lecture_asset["id"]) # set the folder to download ephemeral files
if not os.path.exists(lecture_working_dir): if not os.path.exists(lecture_working_dir):
os.mkdir(lecture_working_dir) os.mkdir(lecture_working_dir)
@ -270,7 +270,7 @@ def parse(data):
handle_irregular_segments(media_info,lecture_title,lecture_working_dir,lecture_path) handle_irregular_segments(media_info,lecture_title,lecture_working_dir,lecture_path)
cleanup(lecture_working_dir) cleanup(lecture_working_dir)
else: else:
print("Lecture " + lecture_title + " is already downloaded, skipping...") print("> Lecture '%s' is already downloaded, skipping..." % lecture_title)
if __name__ == "__main__": if __name__ == "__main__":
if debug: if debug:

View File

@ -2,4 +2,5 @@ mpegdash
sanitize_filename sanitize_filename
tqdm tqdm
requests requests
python-dotenv python-dotenv
protobuf