A Large Update,Improved Aria Download
This commit is contained in:
parent
4f611ea148
commit
16db80c63a
3
Example.py
Normal file
3
Example.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from GMCLCore import *
|
||||||
|
launcher=GMCLCore()
|
||||||
|
launcher.PrintAllLog()
|
@ -1,7 +1,6 @@
|
|||||||
#------------------#
|
#------------------#
|
||||||
import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile,threading
|
import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hashlib,random,subprocess,math,zipfile,threading
|
||||||
#------------------#
|
#------------------#
|
||||||
|
|
||||||
class GMCLCore(object):
|
class GMCLCore(object):
|
||||||
'''The Main Class of the Launcher Core'''
|
'''The Main Class of the Launcher Core'''
|
||||||
#-----------------------------------------------------------------------#
|
#-----------------------------------------------------------------------#
|
||||||
@ -17,7 +16,7 @@ class GMCLCore(object):
|
|||||||
self.__AuthWay=""
|
self.__AuthWay=""
|
||||||
self.__AutoLogOutput=False
|
self.__AutoLogOutput=False
|
||||||
self.__AutoLogPrint=False
|
self.__AutoLogPrint=False
|
||||||
self.__MultiThreadDownload=False
|
self.__AriaDownload=False
|
||||||
self.Log("info","Successful.","__init__")
|
self.Log("info","Successful.","__init__")
|
||||||
#-----------------------------------------------------------------------#
|
#-----------------------------------------------------------------------#
|
||||||
#Log Functions
|
#Log Functions
|
||||||
@ -84,48 +83,49 @@ class GMCLCore(object):
|
|||||||
self.Log("info","Successful.","DisableAutoLogPrint")
|
self.Log("info","Successful.","DisableAutoLogPrint")
|
||||||
#-----------------------------------------------------------------------#
|
#-----------------------------------------------------------------------#
|
||||||
#Download Functions
|
#Download Functions
|
||||||
def Download(self,DownloadFrom,DownloadTo,ThreadNum=20):
|
def Download(self,DownloadFrom,DownloadTo):
|
||||||
'''The multi-thread download function'''
|
'''The multi-thread download function'''
|
||||||
''':DownloadFrom The online url for the file'''
|
''':DownloadFrom The online url for the file'''
|
||||||
''':DownloadTo The local path for the file'''
|
''':DownloadTo The local path for the file'''
|
||||||
''':ThreadNum The number of the thread,the default value is 20'''
|
|
||||||
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()
|
StartTime=time.time()
|
||||||
FileSize=int(requests.head(DownloadFrom,headers=self.__UserAgent).headers['Content-Length'])
|
FileSize=int(requests.head(DownloadFrom,headers=self.__UserAgent).headers['Content-Length'])
|
||||||
if(self.__MultiThreadDownload==True):
|
if(self.__AriaDownload==True):
|
||||||
if(platform.system()=="Windows"):
|
if(platform.system()=="Windows"):
|
||||||
if(os.path.isfile("aria2c.exe")):
|
if(os.path.isfile(self.__LauncherName+"\\rely\\"+"aria2c.exe")):
|
||||||
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||||
else:
|
else:
|
||||||
self.Log("warn","Missed Aria2C.","Download")
|
self.Log("warn","Missed Aria.","Download")
|
||||||
self.DownloadAria2CWin()
|
self.DownloadAriaWin()
|
||||||
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||||
else:
|
else:
|
||||||
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||||
else:
|
else:
|
||||||
with open(DownloadTo,"wb") as FileObject:
|
with open(DownloadTo,"wb") as FileObject:
|
||||||
FileObject.write(requests.get(DownloadFrom).content)
|
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))
|
||||||
def DownloadAria2CWin(self):
|
def DownloadAriaWin(self):
|
||||||
'''The function which was used to download Aria2C environment for windows'''
|
'''The function which was used to download Aria environment for windows'''
|
||||||
|
if(os.path.isdir(self.__LauncherName+"\\rely")==False):
|
||||||
|
self.MakeDir(self.__LauncherName+"\\rely")
|
||||||
if(os.path.isdir("C:\\Program Files (x86)")):
|
if(os.path.isdir("C:\\Program Files (x86)")):
|
||||||
with open("aria2c.exe","wb") as FileObject:
|
with open(self.__LauncherName+"\\rely\\"+"aria2c.exe","wb") as FileObject:
|
||||||
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win64/aria2c.exe",headers=self.__UserAgent).content)
|
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win64/aria2c.exe",headers=self.__UserAgent).content)
|
||||||
else:
|
else:
|
||||||
with open("aria2c.exe","wb") as FileObject:
|
with open(self.__LauncherName+"\\rely\\"+"aria2c.exe","wb") as FileObject:
|
||||||
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win32/aria2c.exe",headers=self.__UserAgent).content)
|
FileObject.write(requests.get("https://resource.ghink.net/aria2c/win32/aria2c.exe",headers=self.__UserAgent).content)
|
||||||
self.Log("info","Success.","DownloadAria2CWin")
|
self.Log("info","Success.","DownloadAriaWin")
|
||||||
def EnableMultiThreadDownload(self):
|
def EnableAriaDownload(self):
|
||||||
'''The function which was used to enable the function of multi-thread download'''
|
'''The function which was used to enable the function of Aria download'''
|
||||||
self.__MultiThreadDownload=True
|
self.__AriaDownload=True
|
||||||
self.Log("info","Successful.","EnableMultiThreadDownload")
|
self.Log("info","Successful.","EnableAriaDownload")
|
||||||
def DisableMultiThreadDownload(self):
|
def DisableAriaDownload(self):
|
||||||
'''The function which was used to disable the function of multi-thread download'''
|
'''The function which was used to disable the function of Aria download'''
|
||||||
self.__MultiThreadDownload=False
|
self.__AriaDownload=False
|
||||||
self.Log("info","Successful.","DisbleMultiThreadDownload")
|
self.Log("info","Successful.","DisbleAriaDownload")
|
||||||
#-----------------------------------------------------------------------#
|
#-----------------------------------------------------------------------#
|
||||||
#File and Dir Functions
|
#File and Dir Functions
|
||||||
def MakeDir(self,Path):
|
def MakeDir(self,Path):
|
Reference in New Issue
Block a user