handle local path redirects

This commit is contained in:
cquest 2023-01-15 09:35:04 +01:00
parent e3292c74bd
commit 1165374824

View File

@ -18,7 +18,11 @@ import requests
def unredir(redir):
r = requests.get(redir, allow_redirects=False)
while r.status_code in {301, 302}:
redir = r.headers.get('Location')
if 'http' not in r.headers.get('Location'):
redir = re.sub(r'(https?://.*)/.*', r'\1', redir) + \
r.headers.get('Location')
else:
redir = r.headers.get('Location')
print('redir', redir)
if '//ow.ly/' in redir or '//bit.ly/' in redir:
redir = redir.replace('https://ow.ly/', 'http://ow.ly/') # only http