aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/lib/utils.py
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-07-21 14:44:11 +0200
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-07-21 14:47:18 +0200
commit92289b32248f4568579edfd5a301e571ade0c284 (patch)
tree2eced0067f8b947c10633c71d09699879ccd68f7 /pyaggr3g470r/lib/utils.py
parentadding a no change return policy (diff)
downloadnewspipe-92289b32248f4568579edfd5a301e571ade0c284.tar.gz
newspipe-92289b32248f4568579edfd5a301e571ade0c284.tar.bz2
newspipe-92289b32248f4568579edfd5a301e571ade0c284.zip
fetching mimetypes with images
Diffstat (limited to 'pyaggr3g470r/lib/utils.py')
-rw-r--r--pyaggr3g470r/lib/utils.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/pyaggr3g470r/lib/utils.py b/pyaggr3g470r/lib/utils.py
index 62284de1..a51b6c3e 100644
--- a/pyaggr3g470r/lib/utils.py
+++ b/pyaggr3g470r/lib/utils.py
@@ -40,14 +40,17 @@ def rebuild_url(url, base_split):
return urllib.parse.urlunsplit(new_split)
-def try_splits(url, *splits):
+def try_get_b64icon(url, *splits):
for split in splits:
if split is None:
continue
rb_url = rebuild_url(url, split)
response = requests.get(rb_url, verify=False, timeout=10)
- if response.ok and 'html' not in response.headers['content-type']:
- return base64.b64encode(response.content).decode('utf8')
+ # if html in content-type, we assume it's a fancy 404 page
+ content_type = response.headers.get('content-type', '')
+ if response.ok and 'html' not in content_type:
+ return content_type + (
+ '\n%s' % base64.b64encode(response.content).decode('utf8'))
return None
bgstack15