on master help sign in
[enh] Add Tineye reverse image search (#3040)

* [enh] Add Tineye reverse image search Other optional parametesr: "&sort=crawl_date" can be appended to search_string to sort results by date. "&domain=example.org" can be implemented to search_string to get results from just one domain. Public instances could get relatively fast timed-out for 3600s. * [enh] Add TIneye to settings.yml Check if that's the right shortcut. * [mod] Fix checks * [mod] Try to fix checks * [mod] Use Four spaces for indentation And set paging back to True Co-authored-by: Noémi Ványi <kvch@users.noreply.github.com>

commit0c351ea36429d881f5bae4161f2aa6a3357bd4cf authorAllen <64094914+allendema@users.noreply.github.com> dateSat 22 Jan 2022, 12:15 (5 years ago) parentfd9d6b5
2 files changed+93
searx/engines/tineye.py+86 searx/settings.yml+7
searx/engines/tineye.pynew file+86
@@ -0,0 +1,86 @@
1+"""
2+Tineye - Reverse search images
3+"""
4+
5+from json import loads
6+from urllib.parse import urlencode
7+
8+from datetime import datetime
9+
10+about = {
11+ "website": "https://tineye.com",
12+ "wikidata_id": "Q2382535",
13+ "use_official_api": False,
14+ "require_api_key": False,
15+ "results": "JSON",
16+}
17+
18+
19+categories = ['images']
20+paging = True
21+
22+safesearch = False
23+
24+
25+base_url = 'https://tineye.com'
26+search_string = '/result_json/?page={page}&{query}'
27+
28+
29+def request(query, params):
30+ params['url'] = base_url +\
31+ search_string.format(
32+ query=urlencode({'url': query}),
33+ page=params['pageno'])
34+
35+ params['headers'].update({
36+ 'Connection': 'keep-alive',
37+ 'Accept-Encoding': 'gzip, defalte, br',
38+ 'Host': 'tineye.com',
39+ 'DNT': '1',
40+ 'TE': 'trailers',
41+ })
42+
43+ return params
44+
45+
46+def response(resp):
47+ results = []
48+ # Define wanted results
49+ json_data = loads(resp.text)
50+ number_of_results = json_data['num_matches']
51+
52+ for i in json_data['matches']:
53+ for i in json_data['matches']:
54+ image_format = i['format']
55+ width = i['width']
56+ height = i['height']
57+ thumbnail_src = i['image_url']
58+ backlink = i['domains'][0]['backlinks'][0]
59+
60+ url = backlink['backlink']
61+ source = backlink['url']
62+ title = backlink['image_name']
63+ img_src = backlink['url']
64+
65+ # Get and convert published date
66+ api_date = backlink['crawl_date'][:-3]
67+ publishedDate = datetime.fromisoformat(api_date)
68+
69+ # Append results
70+ results.append({
71+ 'template': 'images.html',
72+ 'url': url,
73+ 'thumbnail_src': thumbnail_src,
74+ 'source': source,
75+ 'title': title,
76+ 'img_src': img_src,
77+ 'format': image_format,
78+ 'widht': width,
79+ 'height': height,
80+ 'publishedDate': publishedDate,
81+ })
82+
83+ # Append number of results
84+ results.append({'number_of_results': number_of_results})
85+
86+ return results
searx/settings.yml+7
@@ -410,6 +410,13 @@ engines:
410410 timeout: 3.0
411411 disabled : True
412412
413+ - name : tineye
414+ engine : tineye
415+ shortcut : tin
416+ paging : True
417+ timeout : 9.0
418+ disabled : True
419+
413420 - name : etools
414421 engine : etools
415422 shortcut : eto