Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,33 @@ def download_media_ids(self, ids, filepath, progress_mode="inline"):

downloaded_size = 0
print('downloading to {}'.format(filepath))

# Update progress every 10MB
update_interval = 10 * 1024 * 1024 # 10MB in bytes
last_update = 0

with open(filepath, 'wb') as file:
# Iterate over the response in chunks 8K chunks
for chunk in resp.iter_content(chunk_size=8192):
# Write the chunk to the file
file.write(chunk)
if chunk: # filter out keep-alive new chunks
# Write the chunk to the file
file.write(chunk)

# Update the downloaded size
downloaded_size += len(chunk)

# Only update progress every 10MB
if downloaded_size - last_update >= update_interval:
progress = ((downloaded_size / 1024) / 1024)

# Update the downloaded size
downloaded_size += len(chunk)
progress = ((downloaded_size / 1024) / 1024)
if progress_mode == "inline":
# Print the progress
print(f"\rdownloaded: {progress:.2f}MB ({downloaded_size}) bytes", end='')

if progress_mode == "inline":
# Print the progress
print(f"\rdownloaded: {progress:.2f}MB ({downloaded_size}) bytes", end='')
if progress_mode == "newline":
print(f"downloaded: {progress:.2f}MB ({downloaded_size}) bytes")

if progress_mode == "newline":
print(f"downloaded: {progress:.2f}MB ({downloaded_size}) bytes")
last_update = downloaded_size

print("\ndownload completed!")

Expand Down