Use Aria2C to deal Download tasks,Use EnableMultiThreadDownload() To enable it
This commit is contained in:
parent
b4319e5b8e
commit
49e7b89870
30
core.py
30
core.py
@ -15,9 +15,14 @@ class GMCLCore(object):
|
|||||||
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
|
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
|
||||||
self.__Log=[]
|
self.__Log=[]
|
||||||
self.__AuthWay=""
|
self.__AuthWay=""
|
||||||
|
self.__MultiThreadDownload=False
|
||||||
self.Log("info","Successful.","__init__")
|
self.Log("info","Successful.","__init__")
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.Log("info","Successful.","__del__")
|
self.Log("info","Successful.","__del__")
|
||||||
|
def EnableMultiThreadDownload(self):
|
||||||
|
'''The function which was used to enable the function of multi-thread download'''
|
||||||
|
self.__MultiThreadDownload=True
|
||||||
|
self.Log("info","Successful.","EnableMultiThreadDownload")
|
||||||
def Log(self,Type,Text,Function="Anonymous Function",ErrorType="TypeError"):
|
def Log(self,Type,Text,Function="Anonymous Function",ErrorType="TypeError"):
|
||||||
'''The function which was used to manager the log output system'''
|
'''The function which was used to manager the log output system'''
|
||||||
''':Type Type of the log info'''
|
''':Type Type of the log info'''
|
||||||
@ -166,5 +171,28 @@ class GMCLCore(object):
|
|||||||
if(DownloadFrom=="" or DownloadTo==""):
|
if(DownloadFrom=="" or DownloadTo==""):
|
||||||
self.Log("warn","Wrong online address or local address for download.","Download")
|
self.Log("warn","Wrong online address or local address for download.","Download")
|
||||||
else:
|
else:
|
||||||
|
StartTime=time.time()
|
||||||
|
FileSize=int(requests.head(DownloadFrom,headers=self.__UserAgent).headers['Content-Length'])
|
||||||
|
if(self.__MultiThreadDownload==True):
|
||||||
|
if(platform.system()=="Windows"):
|
||||||
|
if(os.path.isfile("aria2c.exe")):
|
||||||
|
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||||
|
else:
|
||||||
|
if(os.path.isdir("C:\\Program Files (x86)")):
|
||||||
|
with open("aria2c.exe","wb") as FileObject:
|
||||||
|
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win64/aria2c.exe",headers=self.__UserAgent).content)
|
||||||
|
else:
|
||||||
|
with open("aria2c.exe","wb") as FileObject:
|
||||||
|
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win32/aria2c.exe",headers=self.__UserAgent).content)
|
||||||
|
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||||
|
else:
|
||||||
|
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||||
|
else:
|
||||||
|
with open(DownloadTo,"wb") as FileObject:
|
||||||
|
FileObject.write(requests.get(DownloadFrom).content)
|
||||||
self.Log("info","Success.","Download")
|
self.Log("info","Success.","Download")
|
||||||
return (str(time.time()-StartTime),filesize // (time.time()-StartTime))
|
return (str(time.time()-StartTime),FileSize // (time.time()-StartTime))
|
||||||
|
|
||||||
|
launcher=GMCLCore()
|
||||||
|
launcher.EnableMultiThreadDownload()
|
||||||
|
launcher.Download("http://mirrors.163.com/centos/8-stream/isos/x86_64/CentOS-Stream-8-x86_64-20201030-boot.iso","test.iso")
|
Reference in New Issue
Block a user