Handle special case for Dropbox links when expanding URLS

This commit is contained in:
Jose Manuel Delicado 2017-09-22 17:30:09 +02:00
parent 11ca3a2190
commit 11703f50fe

View File

@ -22,6 +22,16 @@ class URLShortener (object):
def unshorten(self, url):
try:
r=requests.head(url)
return r.headers['location']
if 'location' in r.headers.keys():
if 'dropbox.com' in r.headers['location']:
return handle_dropbox(r.headers['location'])
else:
return r.headers['location']
except:
return url #we cannot expand
def handle_dropbox(url):
if url.endswith("dl=1"):
return url
else:
return url.replace("dl=0", "dl=1")