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 = ""
# 下载完成标记
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())

@ -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()

@ -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

@ -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()

Loading…
Cancel
Save