summaryrefslogtreecommitdiff
path: root/searx/engines/google_images.py
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarIT.de>2023-03-29 09:47:21 +0200
committerGitHub <noreply@github.com>2023-03-29 09:47:21 +0200
commitf950119ca87363aec81591dc4985f11371aa2b3e (patch)
treeab893ff1f60d8c969ff0f5c2fad0cff49148aa3c /searx/engines/google_images.py
parent64fea2f9cb079bd0055c6a23360097d285204515 (diff)
parent6f9e678346e5978a09ee453a62fa133cdc0ee0bd (diff)
Merge pull request #2269 from return42/locale-revision
Revision of the locale- and language- handling in SearXNG
Diffstat (limited to 'searx/engines/google_images.py')
-rw-r--r--searx/engines/google_images.py49
1 files changed, 28 insertions, 21 deletions
diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py
index 528f8d21d..e6445b1c4 100644
--- a/searx/engines/google_images.py
+++ b/searx/engines/google_images.py
@@ -1,31 +1,38 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
-"""This is the implementation of the google images engine using the google
-internal API used the Google Go Android app.
+"""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).
+- 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
"""
+from typing import TYPE_CHECKING
+
from urllib.parse import urlencode
from json import loads
+from searx.engines.google import fetch_traits # pylint: disable=unused-import
from searx.engines.google import (
- get_lang_info,
+ get_google_info,
time_range_dict,
detect_google_sorry,
)
-# pylint: disable=unused-import
-from searx.engines.google import supported_languages_url, _fetch_supported_languages
+if TYPE_CHECKING:
+ import logging
+ from searx.enginelib.traits import EngineTraits
+
+ logger: logging.Logger
+ traits: EngineTraits
-# pylint: enable=unused-import
# about
about = {
@@ -40,7 +47,6 @@ about = {
# engine dependent config
categories = ['images', 'web']
paging = True
-use_locale_domain = True
time_range_support = True
safesearch = True
send_accept_language_header = True
@@ -51,20 +57,18 @@ filter_mapping = {0: 'images', 1: 'active', 2: 'active'}
def request(query, params):
"""Google-Image search request"""
- lang_info = get_lang_info(params, supported_languages, language_aliases, False)
+ google_info = get_google_info(params, traits)
query_url = (
'https://'
- + lang_info['subdomain']
+ + google_info['subdomain']
+ '/search'
+ "?"
+ urlencode(
{
'q': query,
'tbm': "isch",
- **lang_info['params'],
- 'ie': "utf8",
- 'oe': "utf8",
+ **google_info['params'],
'asearch': 'isch',
'async': '_fmt:json,p:1,ijn:' + str(params['pageno']),
}
@@ -77,9 +81,8 @@ def request(query, params):
query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})
params['url'] = query_url
- params['headers'].update(lang_info['headers'])
- params['headers']['User-Agent'] = 'NSTN/3.60.474802233.release Dalvik/2.1.0 (Linux; U; Android 12; US) gzip'
- params['headers']['Accept'] = '*/*'
+ params['cookies'] = google_info['cookies']
+ params['headers'].update(google_info['headers'])
return params
@@ -111,7 +114,11 @@ def response(resp):
copyright_notice = item["result"].get('iptc', {}).get('copyright_notice')
if copyright_notice:
- result_item['source'] += ' / ' + copyright_notice
+ result_item['source'] += ' | ' + copyright_notice
+
+ freshness_date = item["result"].get("freshness_date")
+ if freshness_date:
+ result_item['source'] += ' | ' + freshness_date
file_size = item.get('gsa', {}).get('file_size')
if file_size: