Compare commits

...

3 Commits

Author SHA1 Message Date
cquest
d022f43aa3 dependencies upgrades 2023-06-02 11:59:57 +02:00
cquest
21ef9375f3 hack to handle UTF8 encoded "Location" header 2023-06-02 11:57:04 +02:00
cquest
5b562ff379 fix endless loop redirects 2023-06-02 11:56:38 +02:00
2 changed files with 9 additions and 8 deletions

View File

@ -1,5 +1,5 @@
feedparser>=6.0.10
Mastodon.py==1.8.0
requests==2.28.1
Mastodon.py==1.8.1
requests==2.31.0
twint @ git+https://github.com/woluxwolu/twint.git
yt-dlp>=2023.3.4

View File

@ -22,16 +22,17 @@ def unredir(redir):
redir_count = redir_count + 1
if redir_count > 10:
break
if 'http' not in r.headers.get('Location'):
redir = re.sub(r'(https?://.*)/.*', r'\1', redir) + \
r.headers.get('Location')
location = r.headers.get('Location')
if 'go.france24.com' in redir:
# decoding hack in case "location" header is UTF-8 encoded (should not !)
location = location.encode("latin1").decode("utf-8")
if 'http' not in location:
redir = re.sub(r'(https?://[^/]*).*$', r'\1', redir) + location
else:
redir = r.headers.get('Location')
# print('redir', redir)
redir = location
if '//ow.ly/' in redir or '//bit.ly/' in redir:
redir = redir.replace('https://ow.ly/', 'http://ow.ly/') # only http
redir = requests.get(redir, allow_redirects=False).headers.get('Location')
# print('redir+', redir)
try:
r = requests.get(redir, allow_redirects=False, timeout=5)
except: