on master help sign in
Removes what looks like tracking parameters
commitb9ada93b3ade2b4268bdc898e2c67b156b4dba92 authorDenis Wernert <deniswernert@gmail.com> dateMon 8 Oct 2018, 14:56 (8 years ago) parentee07a5e
2 files changed+19−7
searx/engines/unsplash.py+16−4 tests/unit/engines/test_unsplash.py+3−3
searx/engines/unsplash.py+16−4
@@ -10,7 +10,7 @@
1010 @parse url, title, img_src, thumbnail_src
1111"""
1212
13−from searx.url_utils import urlencode
13+from searx.url_utils import urlencode, urlparse, urlunparse, parse_qsl
1414from json import loads
1515
1616url = 'https://unsplash.com/'
@@ -20,6 +20,18 @@ page_size = 20
2020paging = True
2121
2222
23+def clean_url(url):
24+ parsed = urlparse(url)
25+ query = [(k, v) for (k, v) in parse_qsl(parsed.query) if k not in ['ixid', 's']]
26+
27+ return urlunparse((parsed.scheme,
28+ parsed.netloc,
29+ parsed.path,
30+ parsed.params,
31+ urlencode(query),
32+ parsed.fragment))
33+
34+
2335def request(query, params):
2436 params['url'] = search_url + urlencode({'query': query, 'page': params['pageno'], 'per_page': page_size})
2537 return params
@@ -32,9 +44,9 @@ def response(resp):
3244 if 'results' in json_data:
3345 for result in json_data['results']:
3446 results.append({'template': 'images.html',
35− 'url': result['links']['html'],
36− 'thumbnail_src': result['urls']['thumb'],
37− 'img_src': result['urls']['raw'],
47+ 'url': clean_url(result['links']['html']),
48+ 'thumbnail_src': clean_url(result['urls']['thumb']),
49+ 'img_src': clean_url(result['urls']['raw']),
3850 'title': result['description'],
3951 'content': ''})
4052 return results
tests/unit/engines/test_unsplash.py+3−3
@@ -32,7 +32,7 @@ class TestUnsplashEngine(SearxTestCase):
3232 self.assertEqual(result[0]['title'], 'low angle photography of swimming penguin')
3333 self.assertEqual(result[0]['url'], 'https://unsplash.com/photos/FY8d721UO_4')
3434 self.assertEqual(result[0]['thumbnail_src'], 'https://images.unsplash.com/photo-1523557148507-1b77641c7e7c?ixlib=rb-0.3.5&q=80\
35−&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&ixid=eyJhcHBfaWQiOjEyMDd9&s=a9b9e56e63efc6f4611a87ce7e9a48f8')
36− self.assertEqual(result[0]['img_src'], 'https://images.unsplash.com/photo-1523557148507-1b77641c7e7c?ixlib=rb-0.3.5\
37−&ixid=eyJhcHBfaWQiOjEyMDd9&s=095c5fc319c5a77c705f49ad63e0f195')
35+&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max')
36+ self.assertEqual(result[0]['img_src'], 'https://images.unsplash.com/photo-1523557148507-1b77641c7e7c\
37+?ixlib=rb-0.3.5')
3838 self.assertEqual(result[0]['content'], '')