logo

searx

My custom branche(s) on searx, a meta-search engine
commit: 01143f48c527ff7bb98b9a9e3d31f087d7d30ca3
parent: 60eb831966a7482ec1bcd7d095241cf2e6fe4dc6
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Fri, 16 Jan 2015 16:26:15 +0100

[enh] image proxification

Diffstat:

Msearx/settings.yml1+
Msearx/webapp.py15+++++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/searx/settings.yml b/searx/settings.yml @@ -8,6 +8,7 @@ server: default_theme : oscar # ui theme https_rewrite : True # Force rewrite result urls. See searx/https_rewrite.py useragent_suffix : "" # suffix of searx_useragent, could contain informations like an email address to the administrator + image_proxy : False # Proxying image results through searx engines: - name : wikipedia diff --git a/searx/webapp.py b/searx/webapp.py @@ -29,6 +29,7 @@ import os from datetime import datetime, timedelta from requests import get as http_get from itertools import chain +from urllib import urlencode from flask import ( Flask, request, render_template, url_for, Response, make_response, redirect, send_from_directory @@ -204,6 +205,18 @@ def url_for_theme(endpoint, override_theme=None, **values): return url_for(endpoint, **values) +def image_proxify(url): + + if url.startswith('//'): + url = 'https:' + url + + if not settings['server'].get('image_proxy') and not request.cookies.get('image_proxy'): + return url + + return '{0}?{1}'.format(url_for('image_proxy'), + urlencode(dict(url=url))) + + def render(template_name, override_theme=None, **kwargs): blocked_engines = request.cookies.get('blocked_engines', '').split(',') @@ -250,6 +263,8 @@ def render(template_name, override_theme=None, **kwargs): # override url_for function in templates kwargs['url_for'] = url_for_theme + kwargs['image_proxify'] = image_proxify + kwargs['get_result_template'] = get_result_template kwargs['theme'] = get_current_theme_name(override=override_theme)