Fixed a UA bug
This commit is contained in:
parent
e5eae0ce1f
commit
040c929bdc
23
main.py
23
main.py
@ -5,15 +5,16 @@ import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hash
|
|||||||
class MultiThreadDownload(threading.Thread):
|
class MultiThreadDownload(threading.Thread):
|
||||||
'''The Class for Multi-Thread Download'''
|
'''The Class for Multi-Thread Download'''
|
||||||
'''Get from Internet and improved by Ghink Network Studio'''
|
'''Get from Internet and improved by Ghink Network Studio'''
|
||||||
def __init__(self,url,startpos,endpos,f):
|
def __init__(self,url,startpos,endpos,f,UA):
|
||||||
super(MultiThreadDownload,self).__init__()
|
super(MultiThreadDownload,self).__init__()
|
||||||
self.url = url
|
self.url=url
|
||||||
self.startpos = startpos
|
self.startpos=startpos
|
||||||
self.endpos = endpos
|
self.endpos=endpos
|
||||||
self.fd = f
|
self.fd=f
|
||||||
|
self.UA=UA
|
||||||
def download(self):
|
def download(self):
|
||||||
headers = {"Range":"bytes=%s-%s"%(self.startpos,self.endpos)}
|
headers=self.UA.update({"Range":"bytes=%s-%s"%(self.startpos,self.endpos)})
|
||||||
res = requests.get(self.url,headers=headers)
|
res=requests.get(self.url,headers=headers)
|
||||||
self.fd.seek(self.startpos)
|
self.fd.seek(self.startpos)
|
||||||
self.fd.write(res.content)
|
self.fd.write(res.content)
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -137,15 +138,13 @@ class GMCLCore(object):
|
|||||||
else:
|
else:
|
||||||
url = DownloadFrom
|
url = DownloadFrom
|
||||||
filename = DownloadTo
|
filename = DownloadTo
|
||||||
filesize = int(requests.head(url).headers['Content-Length'])
|
filesize = int(requests.head(url,headers=self.__UserAgent).headers['Content-Length'])
|
||||||
|
|
||||||
threadnum = ThreadNum
|
threadnum = ThreadNum
|
||||||
threading.BoundedSemaphore(threadnum)
|
threading.BoundedSemaphore(threadnum)
|
||||||
step = filesize // threadnum
|
step = filesize // threadnum
|
||||||
mtd_list = []
|
mtd_list = []
|
||||||
start = 0
|
start = 0
|
||||||
end = -1
|
end = -1
|
||||||
|
|
||||||
tempf = open(filename,'w')
|
tempf = open(filename,'w')
|
||||||
tempf.close()
|
tempf.close()
|
||||||
with open(filename,'rb+') as f:
|
with open(filename,'rb+') as f:
|
||||||
@ -157,9 +156,9 @@ class GMCLCore(object):
|
|||||||
end = filesize
|
end = filesize
|
||||||
dup = os.dup(fileno)
|
dup = os.dup(fileno)
|
||||||
fd = os.fdopen(dup,'rb+',-1)
|
fd = os.fdopen(dup,'rb+',-1)
|
||||||
t = MultiThreadDownload(url,start,end,fd)
|
t = MultiThreadDownload(url,start,end,fd,self.__UserAgent)
|
||||||
t.start()
|
t.start()
|
||||||
mtd_list.append(t)
|
mtd_list.append(t)
|
||||||
|
|
||||||
for i in mtd_list:
|
for i in mtd_list:
|
||||||
i.join()
|
i.join()
|
||||||
|
Reference in New Issue
Block a user