Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Update downloader.py
Jules-WinnfieldX93bb21b3ce2c
diff --git a/downloader.py b/downloader.pyindex bd56dc99d..ae7e3e80a 100644--- a/downloader.py+++ b/downloader.py@@ -42,7 +42,7 @@ def clear():def download(passed_from_main):_path = passed_from_main[0]_item = passed_from_main[1]- j = 1+ attempts = 1try:while True:try:@@ -59,25 +59,25 @@ def download(passed_from_main):log(" Downloading " + filename + "...", Fore.LIGHTBLACK_EX)response = requests.get(_url, stream=True)- fileSizeIncoming = int(response.headers['Content-length'])+ incomingFileSize = int(response.headers['Content-length'])with open(_path+str(filename), "wb") as out_file:for chunk in response.iter_content(chunk_size=50000):if chunk:out_file.write(chunk)del responseif out_file:- fileSizeStored = os.path.getsize(_path + str(filename))- if fileSizeIncoming == fileSizeStored:+ storedFileSize = os.path.getsize(_path + str(filename))+ if incomingFileSize == storedFileSize:breakelse:raise SizeError("File Size Specified: {} bytes, File Size Obtained: {} bytes".format(- fileSizeIncoming, fileSizeStored), "These file sizes don't match")+ incomingFileSize, storedFileSize), "These file sizes don't match")except Exception as e:log(e, Fore.RED)os.remove(_path + str(filename))- log(" Failed attempt " + str(j) + " for " + filename, Fore.RED)+ log(" Failed attempt " + str(attempts) + " for " + filename, Fore.RED)log(" Retrying " + filename + "...", Fore.YELLOW)- j += 1+ attempts += 1except Exception as e:print(e)@@ -89,7 +89,7 @@ if __name__ == '__main__':headers = {'headers': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0'}- total = 0+ totalFiles = 0paths = pathlib.Path(__file__).parent.absolute()clear()@@ -107,16 +107,15 @@ if __name__ == '__main__':for line in file_object:url = line.rstrip()- n = requests.get(url, headers=headers)- a1 = n.text- di = a1[a1.find("<title>") + 7 : a1.find("</title>")]- di = di.split("–")[0]- di = di[7:-1]- di = re.findall('^[^\[]*', di)- di = di[0].rstrip()- di += "/"-- links = []+ html = requests.get(url, headers=headers)+ htmlAsText = html.text+ dirName = htmlAsText[htmlAsText.find("<title>") + 7:htmlAsText.find("</title>")]+ if 'cyberdrop' in url.lower():+ dirName = dirName.split("–")[0]+ dirName = dirName[7:-1]+ dirName = re.findall('^[^\[]*', dirName)+ dirName = dirName[0].rstrip()+ dirName += "/"print("\n======================================================\n")@@ -127,36 +126,30 @@ if __name__ == '__main__':print()input(url + " Couldn't find pictures.")exit()- else:- for item in links:- total += 1- path = str(paths) + "/" + di+ path = str(paths) + "/" + dirNamepath = path.replace('.', '')print()print(" URL " + url)- print(" DIR " + di)+ print(" DIR " + dirName)print()- try:- os.mkdir(path)- except OSError:- log("Creation of directory %s failed" % path, Fore.YELLOW)- else:- print()- print ("Directory %s was created" % path)+ if not (os.path.isdir(dirName)):+ try:+ os.mkdir(path)+ print()+ print ("Directory %s was created" % path)+ except OSError:+ log("Creation of directory %s failed" % path, Fore.YELLOW)print()- total = int(total)- i = 0pass_to_func = []for link in links:pass_to_func.append([path, link])- i += 1print("Downloading " + str(len(pass_to_func)) + " files...")- pool = Pool(processes = multiprocessing.cpu_count())+ pool = Pool(processes=multiprocessing.cpu_count())proc = pool.map_async(download, pass_to_func)proc.wait()pool.close()- ex = input("\nFinished. Press enter to quit.")+ exitText = input("\nFinished. Press enter to quit.")