1. 修复文件未下载成功导致文件无法打开

2. 优化下载进度显示
v1.0.7
kelvin_ben 4 years ago committed by Your Name
parent 20b4f665ac
commit fc51a1f360
  1. 4
      libs/core/__init__.py
  2. 15
      libs/core/download.py
  3. 2
      libs/task/base_task.py
  4. 10
      libs/task/download_task.py

@ -22,6 +22,9 @@ os_type = ""
# 输出路径 # 输出路径
output_path = "" output_path = ""
# 下载完成标记
download_flag = False
class Bootstrapper(object): class Bootstrapper(object):
def __init__(self, path): def __init__(self, path):
@ -39,6 +42,7 @@ class Bootstrapper(object):
global domain_history_path global domain_history_path
global excel_row global excel_row
global download_path global download_path
global download_flag
create_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) create_time = time.strftime("%Y%m%d%H%M%S", time.localtime())

@ -14,11 +14,12 @@ from requests.adapters import HTTPAdapter
class DownloadThreads(threading.Thread): 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) threading.Thread.__init__(self)
self.url = input_path self.url = input_path
self.types = types self.types = types
self.cache_path = cache_path self.cache_path = cache_path
self.file_name = file_name
def __requset__(self): def __requset__(self):
try: try:
@ -45,11 +46,11 @@ class DownloadThreads(threading.Thread):
if chunk: if chunk:
f.write(chunk) f.write(chunk)
count += len(chunk) count += len(chunk)
if time.time() - time1 > 2: if time.time() - time1 > 1:
p = count / length * 100 p = count / length * 100
speed = (count - count_tmp) / 1024 / 1024 / 2 speed = (count - count_tmp) / 1024 / 1024 / 2
count_tmp = count # count_tmp = count
print(name + ': ' + formatFloat(p) + '%' + ' Speed: ' + formatFloat(speed) + 'M/S') print(self.file_name + ': ' + formatFloat(p) + '%' + ' Speed: ' + formatFloat(speed) + 'M/S')
time1 = time.time() time1 = time.time()
f.close() f.close()
else: else:
@ -57,11 +58,11 @@ class DownloadThreads(threading.Thread):
with open(self.cache_path,"w",encoding='utf-8',errors='ignore') as f: with open(self.cache_path,"w",encoding='utf-8',errors='ignore') as f:
f.write(html) f.write(html)
f.close() f.close()
else: cores.download_flag = True
return
except Exception: except Exception:
return return
def formatFloat(num):
return '{:.2f}'.format(num)
def run(self): def run(self):
threadLock = threading.Lock() threadLock = threading.Lock()

@ -77,7 +77,7 @@ class BaseTask(object):
cache_info = DownloadTask().start(self.path,self.types) cache_info = DownloadTask().start(self.path,self.types)
cacar_path = cache_info["path"] cacar_path = cache_info["path"]
types = cache_info["type"] 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.") print("[-] File download failed! Please download the file manually and try again.")
return task_info return task_info

@ -16,13 +16,13 @@ class DownloadTask(object):
create_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) create_time = time.strftime("%Y%m%d%H%M%S", time.localtime())
if path.endswith("apk"): if path.endswith("apk"):
types = "Android" types = "Android"
file_suffix = ".apk" file_name = create_time+ ".apk"
elif path.endswith("ipa"): elif path.endswith("ipa"):
types = "iOS" types = "iOS"
file_suffix = ".ipa" file_name = create_time + ".ipa"
else: else:
types = "WEB" types = "WEB"
file_suffix = ".html" file_name = create_time + ".html"
if not(path.startswith("http://") or path.startswith("https://")): if not(path.startswith("http://") or path.startswith("https://")):
if not os.path.isdir(path): if not os.path.isdir(path):
@ -31,8 +31,8 @@ class DownloadTask(object):
return {"path":self.path,"type":self.types} return {"path":self.path,"type":self.types}
else: else:
print("[*] Detected that the task is not local, preparing to download file......") print("[*] Detected that the task is not local, preparing to download file......")
cache_path = os.path.join(cores.download_path, create_time + file_suffix) cache_path = os.path.join(cores.download_path, file_name)
thread = DownloadThreads(path,cache_path,types) thread = DownloadThreads(path,file_name,cache_path,types)
thread.start() thread.start()
thread.join() thread.join()

Loading…
Cancel
Save