diff --git a/searx/engines/bing_images.py b/searx/engines/bing_images.py index 9d1c22f5a..b8c61c151 100644 --- a/searx/engines/bing_images.py +++ b/searx/engines/bing_images.py @@ -21,12 +21,18 @@ import re # engine dependent config categories = ['images'] paging = True +safesearch = True # search-url base_url = 'https://www.bing.com/' search_string = 'images/search?{query}&count=10&first={offset}' thumb_url = "http://ts1.mm.bing.net/th?id={ihk}" +# safesearch definitions +safesearch_types = {2: 'STRICT', + 1: 'DEMOTE', + 0: 'OFF'} + # do search-request def request(query, params): @@ -43,7 +49,8 @@ def request(query, params): offset=offset) params['cookies']['SRCHHPGUSR'] = \ - 'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0] + 'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0] +\ + '&ADLT=' + safesearch_types.get(params['safesearch'], 'DEMOTE') params['url'] = base_url + search_path diff --git a/searx/engines/blekko_images.py b/searx/engines/blekko_images.py index 2bae9c35e..2e7ec904f 100644 --- a/searx/engines/blekko_images.py +++ b/searx/engines/blekko_images.py @@ -14,11 +14,17 @@ from urllib import urlencode # engine dependent config categories = ['images'] paging = True +safesearch = True # search-url base_url = 'https://blekko.com' search_url = '/api/images?{query}&c={c}' +# safesearch definitions +safesearch_types = {2: '1', + 1: '', + 0: '0'} + # do search-request def request(query, params): @@ -31,6 +37,12 @@ def request(query, params): if params['pageno'] != 1: params['url'] += '&page={pageno}'.format(pageno=(params['pageno']-1)) + # let Blekko know we wan't have profiling + params['cookies']['tag_lesslogging'] = '1' + + # parse safesearch argument + params['cookies']['safesearch'] = safesearch_types.get(params['safesearch'], '') + return params diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py index 092ae6639..1c0e62f5c 100644 --- a/searx/engines/google_images.py +++ b/searx/engines/google_images.py @@ -15,18 +15,25 @@ from json import loads # engine dependent config categories = ['images'] paging = True +safesearch = True # search-url url = 'https://ajax.googleapis.com/' -search_url = url + 'ajax/services/search/images?v=1.0&start={offset}&rsz=large&safe=off&filter=off&{query}' +search_url = url + 'ajax/services/search/images?v=1.0&start={offset}&rsz=large&safe={safesearch}&filter=off&{query}' # do search-request def request(query, params): offset = (params['pageno'] - 1) * 8 + if params['safesearch'] == 0: + safesearch = 'off' + else: + safesearch = 'on' + params['url'] = search_url.format(query=urlencode({'q': query}), - offset=offset) + offset=offset, + safesearch=safesearch) return params diff --git a/searx/search.py b/searx/search.py index 1b16ee02f..79a8ae0a9 100644 --- a/searx/search.py +++ b/searx/search.py @@ -457,6 +457,11 @@ class Search(object): request_params['started'] = time() request_params['pageno'] = self.pageno request_params['language'] = self.lang + try: + # 0 = None, 1 = Moderate, 2 = Strict + request_params['safesearch'] = int(request.cookies.get('safesearch', 1)) + except ValueError: + request_params['safesearch'] = 1 # update request parameters dependent on # search-engine (contained in engines folder) diff --git a/searx/templates/courgette/preferences.html b/searx/templates/courgette/preferences.html index 198bc7ead..18406672c 100644 --- a/searx/templates/courgette/preferences.html +++ b/searx/templates/courgette/preferences.html @@ -59,6 +59,16 @@
+ +