.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.google_images Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

logging logger .Logger
 
dict about
 
list categories = ['images', 'web']
 
bool paging = True
 
int max_page = 50
 
bool time_range_support = True
 
bool safesearch = True
 
bool send_accept_language_header = True
 
dict filter_mapping = {0: 'images', 1: 'active', 2: 'active'}
 

Detailed Description

This is the implementation of the Google Images engine using the internal
Google API used by the Google Go Android app.

This internal API offer results in

- JSON (``_fmt:json``)
- Protobuf_ (``_fmt:pb``)
- Protobuf_ compressed? (``_fmt:pc``)
- HTML (``_fmt:html``)
- Protobuf_ encoded in JSON (``_fmt:jspb``).

.. _Protobuf: https://en.wikipedia.org/wiki/Protocol_Buffers

Function Documentation

◆ request()

searx.engines.google_images.request ( query,
params )
Google-Image search request

Definition at line 57 of file google_images.py.

57def request(query, params):
58 """Google-Image search request"""
59
60 google_info = get_google_info(params, traits)
61
62 query_url = (
63 'https://'
64 + google_info['subdomain']
65 + '/search'
66 + '?'
67 + urlencode({'q': query, 'tbm': "isch", **google_info['params'], 'asearch': 'isch'})
68 # don't urlencode this because wildly different AND bad results
69 # pagination uses Zero-based numbering
70 + f'&async=_fmt:json,p:1,ijn:{params["pageno"] - 1}'
71 )
72
73 if params['time_range'] in time_range_dict:
74 query_url += '&' + urlencode({'tbs': 'qdr:' + time_range_dict[params['time_range']]})
75 if params['safesearch']:
76 query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})
77 params['url'] = query_url
78 params['cookies'] = google_info['cookies']
79 params['headers'].update(google_info['headers'])
80 # this ua will allow getting ~50 results instead of 10. #1641
81 params['headers']['User-Agent'] = (
82 'NSTN/3.60.474802233.release Dalvik/2.1.0 (Linux; U; Android 12;' f' {google_info.get("country", "US")}) gzip'
83 )
84
85 return params
86
87

◆ response()

searx.engines.google_images.response ( resp)
Get response from google's search request

Definition at line 88 of file google_images.py.

88def response(resp):
89 """Get response from google's search request"""
90 results = []
91
92 detect_google_sorry(resp)
93
94 json_start = resp.text.find('{"ischj":')
95 json_data = loads(resp.text[json_start:])
96
97 for item in json_data["ischj"].get("metadata", []):
98 result_item = {
99 'url': item["result"]["referrer_url"],
100 'title': item["result"]["page_title"],
101 'content': item["text_in_grid"]["snippet"],
102 'source': item["result"]["site_title"],
103 'resolution': f'{item["original_image"]["width"]} x {item["original_image"]["height"]}',
104 'img_src': item["original_image"]["url"],
105 'thumbnail_src': item["thumbnail"]["url"],
106 'template': 'images.html',
107 }
108
109 author = item["result"].get('iptc', {}).get('creator')
110 if author:
111 result_item['author'] = ', '.join(author)
112
113 copyright_notice = item["result"].get('iptc', {}).get('copyright_notice')
114 if copyright_notice:
115 result_item['source'] += ' | ' + copyright_notice
116
117 freshness_date = item["result"].get("freshness_date")
118 if freshness_date:
119 result_item['source'] += ' | ' + freshness_date
120
121 file_size = item.get('gsa', {}).get('file_size')
122 if file_size:
123 result_item['source'] += ' (%s)' % file_size
124
125 results.append(result_item)
126
127 return results

Variable Documentation

◆ about

dict searx.engines.google_images.about
Initial value:
1= {
2 "website": 'https://images.google.com',
3 "wikidata_id": 'Q521550',
4 "official_api_documentation": 'https://developers.google.com/custom-search',
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 37 of file google_images.py.

◆ categories

list searx.engines.google_images.categories = ['images', 'web']

Definition at line 47 of file google_images.py.

◆ filter_mapping

dict searx.engines.google_images.filter_mapping = {0: 'images', 1: 'active', 2: 'active'}

Definition at line 54 of file google_images.py.

◆ logger

logging searx.engines.google_images.logger .Logger

Definition at line 32 of file google_images.py.

◆ max_page

int searx.engines.google_images.max_page = 50

Definition at line 49 of file google_images.py.

◆ paging

bool searx.engines.google_images.paging = True

Definition at line 48 of file google_images.py.

◆ safesearch

bool searx.engines.google_images.safesearch = True

Definition at line 51 of file google_images.py.

◆ send_accept_language_header

bool searx.engines.google_images.send_accept_language_header = True

Definition at line 52 of file google_images.py.

◆ time_range_support

bool searx.engines.google_images.time_range_support = True

Definition at line 50 of file google_images.py.