How to create a progress bar for downloading files in Python

PHOTO EMBED

Wed Nov 29 2023 15:29:23 GMT+0000 (Coordinated Universal Time)

Saved by @amramroo ##python #coding #progressbar

import requests
from tqdm import tqdm

url = 'https://player.vimeo.com/external/121142413.sd.mp4?s=1b8ed80f9ce01d9ecf4af3eb12c879e00f29850f&profile_id=112&oauth2_token_id=57447761'

res = requests.get(url, stream = True)
total_size = int(res.headers.get('content-length', 0))
progress_bar = tqdm(total = total_size, unit = 'iB', unit_scale = True)

with open('video.mp4', 'wb') as file:
    for data in res.iter_content(1024):
        file.write(data)
        progress_bar.update(len(data))


progress_bar.close()
content_copyCOPY

https://dev.to/amr2018/how-to-create-a-progress-bar-for-downloading-files-in-python-2a8b