2012-04-26 16:25:04 +00:00
|
|
|
import sys
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
import urllib
|
|
|
|
url_lib = urllib
|
|
|
|
elif sys.version_info[0] == 3:
|
|
|
|
import urllib.request
|
|
|
|
url_lib = urllib.request
|
|
|
|
|
|
|
|
def fetch_file(url):
|
2014-06-19 17:58:50 +00:00
|
|
|
print("trying %s" % url)
|
2012-04-26 16:25:04 +00:00
|
|
|
try:
|
2014-06-19 17:58:50 +00:00
|
|
|
local = dict(url_lib.urlopen(url).info())
|
|
|
|
if "Content-Disposition" in local:
|
|
|
|
key_name = "Content-Disposition"
|
|
|
|
elif "content-disposition" in local:
|
|
|
|
key_name = "content-disposition"
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
local = local[key_name].split("=")[1]
|
2012-04-26 16:25:04 +00:00
|
|
|
url_lib.urlretrieve(url, local)
|
|
|
|
return local
|
2014-06-19 17:58:50 +00:00
|
|
|
except IOError:
|
2012-04-26 16:25:04 +00:00
|
|
|
return False
|