From fc51a1f3608758b41e3f1c23c26c2247fb1f92b0 Mon Sep 17 00:00:00 2001 From: kelvin_ben Date: Thu, 19 Nov 2020 16:55:50 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9C=AA=E4=B8=8B=E8=BD=BD=E6=88=90=E5=8A=9F=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=97=A0=E6=B3=95=E6=89=93=E5=BC=80=202.=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD=E8=BF=9B=E5=BA=A6=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/core/__init__.py | 4 ++++ libs/core/download.py | 15 ++++++++------- libs/task/base_task.py | 2 +- libs/task/download_task.py | 10 +++++----- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/libs/core/__init__.py b/libs/core/__init__.py index eb825c2..0a4cfcc 100644 --- a/libs/core/__init__.py +++ b/libs/core/__init__.py @@ -22,6 +22,9 @@ os_type = "" # 输出路径 output_path = "" +# 下载完成标记 +download_flag = False + class Bootstrapper(object): def __init__(self, path): @@ -39,6 +42,7 @@ class Bootstrapper(object): global domain_history_path global excel_row global download_path + global download_flag create_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) diff --git a/libs/core/download.py b/libs/core/download.py index 57a78da..081eb95 100644 --- a/libs/core/download.py +++ b/libs/core/download.py @@ -14,11 +14,12 @@ from requests.adapters import HTTPAdapter class DownloadThreads(threading.Thread): - def __init__(self,input_path,cache_path,types): + def __init__(self,input_path,file_name,cache_path,types): threading.Thread.__init__(self) self.url = input_path self.types = types self.cache_path = cache_path + self.file_name = file_name def __requset__(self): try: @@ -45,11 +46,11 @@ class DownloadThreads(threading.Thread): if chunk: f.write(chunk) count += len(chunk) - if time.time() - time1 > 2: + if time.time() - time1 > 1: p = count / length * 100 speed = (count - count_tmp) / 1024 / 1024 / 2 - count_tmp = count - print(name + ': ' + formatFloat(p) + '%' + ' Speed: ' + formatFloat(speed) + 'M/S') + # count_tmp = count + print(self.file_name + ': ' + formatFloat(p) + '%' + ' Speed: ' + formatFloat(speed) + 'M/S') time1 = time.time() f.close() else: @@ -57,11 +58,11 @@ class DownloadThreads(threading.Thread): with open(self.cache_path,"w",encoding='utf-8',errors='ignore') as f: f.write(html) f.close() - else: - return + cores.download_flag = True except Exception: return - + def formatFloat(num): + return '{:.2f}'.format(num) def run(self): threadLock = threading.Lock() diff --git a/libs/task/base_task.py b/libs/task/base_task.py index 38d56b6..a0a605d 100644 --- a/libs/task/base_task.py +++ b/libs/task/base_task.py @@ -77,7 +77,7 @@ class BaseTask(object): cache_info = DownloadTask().start(self.path,self.types) cacar_path = cache_info["path"] types = cache_info["type"] - if not os.path.exists(cacar_path): + if not os.path.exists(cacar_path) and cores.download_flag: print("[-] File download failed! Please download the file manually and try again.") return task_info diff --git a/libs/task/download_task.py b/libs/task/download_task.py index 17da233..dc4024a 100644 --- a/libs/task/download_task.py +++ b/libs/task/download_task.py @@ -16,13 +16,13 @@ class DownloadTask(object): create_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) if path.endswith("apk"): types = "Android" - file_suffix = ".apk" + file_name = create_time+ ".apk" elif path.endswith("ipa"): types = "iOS" - file_suffix = ".ipa" + file_name = create_time + ".ipa" else: types = "WEB" - file_suffix = ".html" + file_name = create_time + ".html" if not(path.startswith("http://") or path.startswith("https://")): if not os.path.isdir(path): @@ -31,8 +31,8 @@ class DownloadTask(object): return {"path":self.path,"type":self.types} else: print("[*] Detected that the task is not local, preparing to download file......") - cache_path = os.path.join(cores.download_path, create_time + file_suffix) - thread = DownloadThreads(path,cache_path,types) + cache_path = os.path.join(cores.download_path, file_name) + thread = DownloadThreads(path,file_name,cache_path,types) thread.start() thread.join()