| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import os
- import requests
- DEPS_FILE = "deps.txt"
- SAVE_DIR = "downloads"
- os.makedirs(SAVE_DIR, exist_ok=True)
- def download_file(filename, url):
- save_path = os.path.join(SAVE_DIR, filename)
- print(f"\nStart download:")
- print(f"Filename: {filename}")
- print(f"Link: {url}")
- r = requests.get(url, stream=True, timeout=60)
- r.raise_for_status()
- total = 0
- with open(save_path, "wb") as f:
- for chunk in r.iter_content(chunk_size=8192):
- if chunk:
- f.write(chunk)
- total += len(chunk)
- print(f"Download finished: {save_path}")
- print(f"File size: {round(total / 1024 / 1024, 2)} MB")
- def main():
- with open(DEPS_FILE, "r", encoding="utf-8") as f:
- lines = f.readlines()
- for line in lines:
- line = line.strip()
- if not line:
- continue
- if line.startswith("#"):
- continue
- try:
- filename, url = line.split("|", 1)
- download_file(
- filename.strip(),
- url.strip()
- )
- except Exception as e:
- print(f"\nDownload failed:")
- print(line)
- print(e)
- if __name__ == "__main__":
- main()
|