forked from chrisdonahue/ddc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_download.py
More file actions
51 lines (41 loc) · 1.31 KB
/
Copy pathtest_download.py
File metadata and controls
51 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import requests
import zipfile
import sys
URLS = [
"https://zenius-i-vanisher.com/v5.2/download.php?type=ddrpack&categoryid=1509", # A3
]
DOWNLOAD_DIR = "data/raw"
EXTRACT_DIR = os.path.join(DOWNLOAD_DIR, "ddr_official")
if not os.path.exists(EXTRACT_DIR):
os.makedirs(EXTRACT_DIR)
def download_url(url, dest_path):
print(f"Downloading {url}...")
sys.stdout.flush()
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
try:
r = requests.get(url, stream=True, headers=headers, timeout=30)
r.raise_for_status()
with open(dest_path, "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Downloaded to {dest_path}")
sys.stdout.flush()
return True
except Exception as e:
print(f"Error downloading {url}: {e}")
sys.stdout.flush()
return False
def main():
print(f"Starting single download test...")
sys.stdout.flush()
url = URLS[0]
temp_zip = os.path.join(DOWNLOAD_DIR, "temp_download_test.zip")
if download_url(url, temp_zip):
print("Download successful.")
else:
print("Download failed.")
if __name__ == "__main__":
main()