From 11703f50feffac41ed5dba50f58d5bd9581c20ed Mon Sep 17 00:00:00 2001 From: Jose Manuel Delicado Date: Fri, 22 Sep 2017 17:30:09 +0200 Subject: [PATCH] Handle special case for Dropbox links when expanding URLS --- src/url_shortener/shorteners/url_shortener.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/url_shortener/shorteners/url_shortener.py b/src/url_shortener/shorteners/url_shortener.py index 3335b1eb..6388dc0d 100644 --- a/src/url_shortener/shorteners/url_shortener.py +++ b/src/url_shortener/shorteners/url_shortener.py @@ -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")