Amazing-Python-Scripts
40 строк · 930.0 Байт
1"""
2File Downloader
3
4This python script will help users to download any kind of files, irrespective of their size from the internet.<br>
5You just need to have the url and you are good to go!
6"""
7import os8import requests9from tqdm import tqdm10import math11import time12
13url = input("Enter the url of the file you want to download: ")14
15r = requests.get(url)16# receives data from the url
17
18file_size = int(r.headers['Content-Length'])19chunk_size = 25620
21"""Chunk size is the
22number of bytes downloaded at a time
23"""
24
25r = requests.get(url, stream=True)26
27"""streams=True ensures that
28will not get data at once, but will get data one by one
29
30"""
31
32extension = (os.path.splitext(url))[-1]33file = "file"+extension34
35iterations = math.ceil(file_size/chunk_size)36
37with open(file, "wb") as file:38for chunk in tqdm(r.iter_content(chunk_size=chunk_size), total=iterations):39time.sleep(0.5)40file.write(chunk)41