def get(url):
# Build and open the URL
opener = urllib2.build_opener()
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
response = opener.open(url)
# HLTV redicrects to a .rar or .zip file
final_url = response.geturl()
# Gets the filename (everything after the last trailing /)
filename = final_url.rsplit('/', 1)[-1]
# Gets the Content-Length from the metadata from final_url
filesize = (int(urllib.urlopen(final_url).info().getheaders("Content-Length")[0])/1024)/1024
# Tell user we are downloading filesize
print "Starting %s: %s MB." % (filename, filesize)
# Downloads the file to the directory the user enters
urllib.urlretrieve(final_url, directory+"/"+filename)
# Tell user the current status and file information
print "Completed %s: %s MB." % (filename, filesize)
return filesize
评论列表
文章目录