GUI: Implement download GUI class

Unifies all download UIs
This commit is contained in:
Mykola Grymalyuk
2023-05-07 17:41:46 -06:00
parent bd70c4a24a
commit 3ef6e4a853
6 changed files with 445 additions and 39 deletions

View File

@@ -9,6 +9,7 @@ import threading
import logging
import enum
import hashlib
import atexit
from pathlib import Path
from resources import utilities
@@ -340,6 +341,7 @@ class DownloadObject:
response = NetworkUtilities().get(self.url, stream=True, timeout=10)
with open(self.filepath, 'wb') as file:
atexit.register(self.stop)
for i, chunk in enumerate(response.iter_content(1024 * 1024 * 4)):
if self.should_stop:
raise Exception("Download stopped")
@@ -407,7 +409,10 @@ class DownloadObject:
if self.total_file_size == 0.0:
logging.error("- File size is 0, cannot calculate time remaining")
return -1
return (self.total_file_size - self.downloaded_file_size) / self.get_speed()
speed = self.get_speed()
if speed <= 0:
return -1
return (self.total_file_size - self.downloaded_file_size) / speed
def get_file_size(self) -> float: