Skip to content

Bulk asynchronous downloader for multiple file hosts

Added setting for timeout, default is 30 seconds.

Mitch Petersen4b2949df5e98
diff --git a/downloader.py b/downloader.py
index 383b9557b..cbe144541 100644
--- a/downloader.py
+++ b/downloader.py
@@ -42,6 +42,7 @@ def clear():
def download(passed_from_main):
_path = passed_from_main[0]
_item = passed_from_main[1]
+ _timeout = passed_from_main[2]
attempts = 1
attemptsToTry = (settings.file_attempts + 1) if settings.file_attempts != 0 else 0
try:
@@ -74,7 +75,7 @@ def download(passed_from_main):
headers['Range'] = f'bytes={storedFileSize}-'
resume = True
- response = requests.get(_url, stream=True, timeout=30, headers=headers)
+ response = requests.get(_url, stream=True, timeout=_timeout, headers=headers)
incomingFileSize = int(response.headers['Content-length'])
log(" Downloading " + filename + "...", Fore.LIGHTBLACK_EX)
@@ -125,6 +126,7 @@ if __name__ == '__main__':
cpu_count = settings.threads if settings.threads != 0 else multiprocessing.cpu_count()
downloadFolder = settings.download_folder
+ timeout = settings.timeout
if downloadFolder == "./Downloads/":
if not os.path.exists(downloadFolder):
@@ -194,7 +196,7 @@ if __name__ == '__main__':
pass_to_func = []
for link in links:
- pass_to_func.append([path, link])
+ pass_to_func.append([path, link, timeout])
print("Downloading " + str(len(pass_to_func)) + " files...")
pool = Pool(processes=cpu_count)
diff --git a/settings.py b/settings.py
index 504b00f11..901265219 100644
--- a/settings.py
+++ b/settings.py
@@ -3,7 +3,9 @@
# threads = 0 (Will run all threads), **this is not the same as cores.**
# download_folder = "./Downloads/" will download in the CyberDropDownloader folder
# file_attempts = 0 (will try infinitely), making it 5 as an example will try to download 5 times and then skip.
+# timeout is measured in seconds
threads = 0
download_folder = "./Downloads/"
file_attempts = 0
+timeout = 30
\ No newline at end of file