Compare commits

...
1 Commits
Author SHA1 Message Date
sisungo ed7d0b5680 fix: source_url does not support file://
Signed-off-by: sisungo <[email protected]>
2026-07-04 19:17:40 +08:00
+39
View File
@@ -30,6 +30,45 @@ def download(url, output):
last_percent = percent
try:
if url.startswith("file://"):
file_path = url[7:]
if not os.path.exists(file_path):
raise Exception("File not found: " + file_path)
total_size = os.path.getsize(file_path)
if total_size <= 0:
print("Copying...")
with open(file_path, "rb") as src, open(output, "wb") as dst:
while True:
chunk = src.read(8192)
if not chunk:
break
dst.write(chunk)
print("Download completed: " + output)
return output
sys.stdout.write("downloading... 0%")
sys.stdout.flush()
with open(file_path, "rb") as src, open(output, "wb") as dst:
downloaded = 0
block_size = 8192
while True:
chunk = src.read(block_size)
if not chunk:
break
dst.write(chunk)
downloaded += len(chunk)
percent = int(downloaded * 100 / total_size)
report_progress(percent)
if last_percent != 100:
report_progress(100)
sys.stdout.write("\n")
print("Download completed: " + output)
return output
req = urllib.request.Request(url, method="GET")
req.add_header(
"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"