Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
Little refactoring Removed trailing spaces Fixed typo Fixed variables scope conflict
kekal72694ec54210
diff --git a/downloader.py b/downloader.pyindex 221db992e..584e7d049 100644--- a/downloader.py+++ b/downloader.py@@ -10,7 +10,7 @@ from colorama import Fore, Stylefrom geturls import Extrair_Linksfrom multiprocessing import Poolimport multiprocessing-from time import sleep+def log(text, style):print(style + str(text) + Style.RESET_ALL)@@ -18,27 +18,30 @@ def log(text, style):def clear():os.system('cls' if os.name == 'nt' else 'clear')-++def download(passed_from_main):- path = passed_from_main[0]- item = passed_from_main[1]- i=1+ _path = passed_from_main[0]+ _item = passed_from_main[1]+ j = 1try:- while(True):+ while True:try:- filename = item[item.rfind("/") + 1:]- url = item-+ filename = _item[_item.rfind("/") + 1:]+ _url = _item+if filename == "cyberdrop.me-downloaders":+break-- if os.path.isfile(path+str(filename)):++ if os.path.isfile(_path + str(filename)):log(" " + filename + " already exists.", Fore.LIGHTBLACK_EX)break-+log(" Downloading " + filename + "...", Fore.LIGHTBLACK_EX)- response = requests.get(url, stream=True)- with open(path+str(filename), "wb") as out_file:++ response = requests.get(_url, stream=True)+ with open(_path+str(filename), "wb") as out_file:for chunk in response.iter_content(chunk_size=None):if chunk:out_file.write(chunk)@@ -47,18 +50,19 @@ def download(passed_from_main):breakexcept Exception as e:log(e, Fore.RED)- os.remove(path+str(filename))- log("Failed attempt " + str(i) + " for " + filename + "\n", Fore.RED)+ os.remove(_path + str(filename))+ log("Failed attempt " + str(j) + " for " + filename + "\n", Fore.RED)log("Retrying "+ filename + "...", Fore.YELLOW)- i+=1-+ j += 1+except Exception as e:print(e)print("Failed to Download")-+if __name__ == '__main__':log("", Fore.RESET)- hearders = {'headers':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0'}++ headers = {'headers': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0'}total = 0paths = pathlib.Path(__file__).parent.absolute()@@ -68,9 +72,9 @@ if __name__ == '__main__':if os.path.isfile("URLs.txt"):print("URLs.txt exists")else:- f = open("URLs.txt", "w+");+ f = open("URLs.txt", "w+")print("URLs.txt created")-+if os.stat("URLs.txt").st_size == 0:print("Please put URLs in URLs.txt")@@ -78,13 +82,13 @@ if __name__ == '__main__':for line in file_object:url = line.rstrip()- n = requests.get(url, headers=hearders)+ n = requests.get(url, headers=headers)a1 = n.textdi = a1[a1.find("<title>") + 7 : a1.find("</title>")]di = di.split("–")[0]di = di[7:-1]di = re.sub('[^\w\-_()\. ]', '_', di)- di = di + "/"+ di += "/"links = []@@ -93,13 +97,13 @@ if __name__ == '__main__':print("\nCollecting file links from " + url + "...")links = Extrair_Links(url)- if links == None:+ if links is None:print()input(url + " Couldn't find pictures.")exit()else:for item in links:- total = total + 1+ total += 1path = str(paths) + "/" + diprint()@@ -121,7 +125,7 @@ if __name__ == '__main__':for link in links:pass_to_func.append([path, link])i += 1-+print("Downloading " + str(len(pass_to_func)) + " files...")pool = Pool(processes = multiprocessing.cpu_count())proc = pool.map_async(download, pass_to_func)