Fixed a UA bug

This commit is contained in:
Bigsk 2020-11-07 22:26:28 +08:00
parent e5eae0ce1f
commit 040c929bdc
2 changed files with 11 additions and 12 deletions

0
1.iso Normal file
View File

23
main.py
View File

@ -5,15 +5,16 @@ import os,requests,json,time,sys,psutil,string,platform,glob,getpass,shutil,hash
class MultiThreadDownload(threading.Thread):
'''The Class for Multi-Thread Download'''
'''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__()
self.url = url
self.startpos = startpos
self.endpos = endpos
self.fd = f
self.url=url
self.startpos=startpos
self.endpos=endpos
self.fd=f
self.UA=UA
def download(self):
headers = {"Range":"bytes=%s-%s"%(self.startpos,self.endpos)}
res = requests.get(self.url,headers=headers)
headers=self.UA.update({"Range":"bytes=%s-%s"%(self.startpos,self.endpos)})
res=requests.get(self.url,headers=headers)
self.fd.seek(self.startpos)
self.fd.write(res.content)
def run(self):
@ -137,15 +138,13 @@ class GMCLCore(object):
else:
url = DownloadFrom
filename = DownloadTo
filesize = int(requests.head(url).headers['Content-Length'])
filesize = int(requests.head(url,headers=self.__UserAgent).headers['Content-Length'])
threadnum = ThreadNum
threading.BoundedSemaphore(threadnum)
step = filesize // threadnum
mtd_list = []
start = 0
end = -1
tempf = open(filename,'w')
tempf.close()
with open(filename,'rb+') as f:
@ -157,9 +156,9 @@ class GMCLCore(object):
end = filesize
dup = os.dup(fileno)
fd = os.fdopen(dup,'rb+',-1)
t = MultiThreadDownload(url,start,end,fd)
t = MultiThreadDownload(url,start,end,fd,self.__UserAgent)
t.start()
mtd_list.append(t)
for i in mtd_list:
for i in mtd_list:
i.join()