mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-08 05:33:34 +00:00
Handle Google web servers returning no file size info
This commit is contained in:
12
gam.py
12
gam.py
@ -695,7 +695,10 @@ def geturl(url, dst):
|
|||||||
u = urllib2.urlopen(url)
|
u = urllib2.urlopen(url)
|
||||||
f = open(dst, 'wb')
|
f = open(dst, 'wb')
|
||||||
meta = u.info()
|
meta = u.info()
|
||||||
file_size = int(meta.getheaders(u'Content-Length')[0])
|
try:
|
||||||
|
file_size = int(meta.getheaders(u'Content-Length')[0])
|
||||||
|
except IndexError:
|
||||||
|
file_size = -1
|
||||||
file_size_dl = 0
|
file_size_dl = 0
|
||||||
block_sz = 8192
|
block_sz = 8192
|
||||||
while True:
|
while True:
|
||||||
@ -704,8 +707,11 @@ def geturl(url, dst):
|
|||||||
break
|
break
|
||||||
file_size_dl += len(buffer)
|
file_size_dl += len(buffer)
|
||||||
f.write(buffer)
|
f.write(buffer)
|
||||||
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
|
if file_size != -1:
|
||||||
status = status + chr(8)*(len(status)+1)
|
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
|
||||||
|
else:
|
||||||
|
status = r"%10d [unknown size]" % (file_size_dl)
|
||||||
|
status = status + chr(8)*(len(status)+1)
|
||||||
print status,
|
print status,
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user