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
|
||||
#------------------#
|
||||
|
||||
class GMCLCore(object):
|
||||
'''The Main Class of the Launcher Core'''
|
||||
#-----------------------------------------------------------------------#
|
||||
@ -17,7 +16,7 @@ class GMCLCore(object):
|
||||
self.__AuthWay=""
|
||||
self.__AutoLogOutput=False
|
||||
self.__AutoLogPrint=False
|
||||
self.__MultiThreadDownload=False
|
||||
self.__AriaDownload=False
|
||||
self.Log("info","Successful.","__init__")
|
||||
#-----------------------------------------------------------------------#
|
||||
#Log Functions
|
||||
@ -84,48 +83,49 @@ class GMCLCore(object):
|
||||
self.Log("info","Successful.","DisableAutoLogPrint")
|
||||
#-----------------------------------------------------------------------#
|
||||
#Download Functions
|
||||
def Download(self,DownloadFrom,DownloadTo,ThreadNum=20):
|
||||
def Download(self,DownloadFrom,DownloadTo):
|
||||
'''The multi-thread download function'''
|
||||
''':DownloadFrom The online url 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==""):
|
||||
self.Log("warn","Wrong online address or local address for download.","Download")
|
||||
else:
|
||||
StartTime=time.time()
|
||||
FileSize=int(requests.head(DownloadFrom,headers=self.__UserAgent).headers['Content-Length'])
|
||||
if(self.__MultiThreadDownload==True):
|
||||
if(self.__AriaDownload==True):
|
||||
if(platform.system()=="Windows"):
|
||||
if(os.path.isfile("aria2c.exe")):
|
||||
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||
if(os.path.isfile(self.__LauncherName+"\\rely\\"+"aria2c.exe")):
|
||||
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||
else:
|
||||
self.Log("warn","Missed Aria2C.","Download")
|
||||
self.DownloadAria2CWin()
|
||||
os.system("aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||
self.Log("warn","Missed Aria.","Download")
|
||||
self.DownloadAriaWin()
|
||||
os.system(self.__LauncherName+"\\rely\\"+"aria2c.exe -o "+DownloadTo+" "+DownloadFrom+" -U \""+self.__UserAgent['User-Agent']+"\"")
|
||||
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:
|
||||
with open(DownloadTo,"wb") as FileObject:
|
||||
FileObject.write(requests.get(DownloadFrom).content)
|
||||
self.Log("info","Success.","Download")
|
||||
return (str(time.time()-StartTime),FileSize // (time.time()-StartTime))
|
||||
def DownloadAria2CWin(self):
|
||||
'''The function which was used to download Aria2C environment for windows'''
|
||||
def DownloadAriaWin(self):
|
||||
'''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)")):
|
||||
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)
|
||||
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)
|
||||
self.Log("info","Success.","DownloadAria2CWin")
|
||||
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 DisableMultiThreadDownload(self):
|
||||
'''The function which was used to disable the function of multi-thread download'''
|
||||
self.__MultiThreadDownload=False
|
||||
self.Log("info","Successful.","DisbleMultiThreadDownload")
|
||||
self.Log("info","Success.","DownloadAriaWin")
|
||||
def EnableAriaDownload(self):
|
||||
'''The function which was used to enable the function of Aria download'''
|
||||
self.__AriaDownload=True
|
||||
self.Log("info","Successful.","EnableAriaDownload")
|
||||
def DisableAriaDownload(self):
|
||||
'''The function which was used to disable the function of Aria download'''
|
||||
self.__AriaDownload=False
|
||||
self.Log("info","Successful.","DisbleAriaDownload")
|
||||
#-----------------------------------------------------------------------#
|
||||
#File and Dir Functions
|
||||
def MakeDir(self,Path):
|
Reference in New Issue
Block a user