├── README.md └── python /README.md: -------------------------------------------------------------------------------- 1 | # Download Script 2 | 3 | This is a simple Python script to download files from a given URL. 4 | 5 | ## Requirements 6 | 7 | - Python 3.x 8 | - `requests` library 9 | - `tqdm` library 10 | 11 | ## Installation 12 | 13 | 1. Clone this repository: 14 | ```bash 15 | git clone https://github.com/yourusername/download_script.git 16 | ``` 17 | 2. Navigate to the project directory: 18 | ```bash 19 | cd download_script 20 | ``` 21 | 3. Install the required libraries: 22 | ```bash 23 | pip install -r requirements.txt 24 | ``` 25 | 26 | ## Usage 27 | 28 | Run the script and follow the prompts: 29 | ```bash 30 | python download.py 31 | -------------------------------------------------------------------------------- /python: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | from tqdm import tqdm 4 | 5 | def download_file(url, save_path, chunk_size=1024): 6 | response = requests.get(url, stream=True) 7 | total_size = int(response.headers.get('content-length', 0)) 8 | 9 | with open(save_path, 'wb') as file, tqdm( 10 | desc=save_path, 11 | total=total_size, 12 | unit='B', 13 | unit_scale=True, 14 | unit_divisor=1024, 15 | ) as bar: 16 | for chunk in response.iter_content(chunk_size=chunk_size): 17 | bar.update(len(chunk)) 18 | file.write(chunk) 19 | 20 | if __name__ == "__main__": 21 | url = input("Enter the URL of the file to download: ") 22 | save_dir = input("Enter the directory to save the file: ") 23 | 24 | if not os.path.exists(save_dir): 25 | os.makedirs(save_dir) 26 | 27 | file_name = url.split('/')[-1] 28 | save_path = os.path.join(save_dir, file_name) 29 | 30 | download_file(url, save_path) 31 | print(f"File downloaded to: {save_path}") 32 | --------------------------------------------------------------------------------