Handle Google web servers returning no file size info

This commit is contained in:
Jay Lee
2014-09-30 09:04:06 -04:00
parent f233f7505c
commit e46af32638

6
gam.py
View File

@ -695,7 +695,10 @@ def geturl(url, dst):
u = urllib2.urlopen(url)
f = open(dst, 'wb')
meta = u.info()
try:
file_size = int(meta.getheaders(u'Content-Length')[0])
except IndexError:
file_size = -1
file_size_dl = 0
block_sz = 8192
while True:
@ -704,7 +707,10 @@ def geturl(url, dst):
break
file_size_dl += len(buffer)
f.write(buffer)
if file_size != -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,
f.close()