This commit is contained in:
Bnyro 2024-10-15 15:28:57 +02:00 committed by GitHub
commit f616dd3d07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 102 additions and 19 deletions

View file

@ -31,6 +31,7 @@ ENGINE_DEFAULT_ARGS = {
"engine_type": "online",
"paging": False,
"time_range_support": False,
"license_filter_support": False,
"safesearch": False,
# settings.yml
"categories": ["general"],

View file

@ -37,6 +37,7 @@ categories = ['images', 'web']
paging = True
safesearch = True
time_range_support = True
license_filter_support = True
base_url = 'https://www.bing.com/images/async'
"""Bing (Images) search URL"""
@ -47,6 +48,7 @@ time_map = {
'month': 60 * 24 * 31,
'year': 60 * 24 * 365,
}
license_map = {'public': 'L1', 'freetouse': 'L2_L3_L5_L6', 'commercial': ''}
def request(query, params):
@ -69,8 +71,12 @@ def request(query, params):
# time range
# - example: one year (525600 minutes) 'qft=+filterui:age-lt525600'
query_params['qft'] = ''
if params['time_range']:
query_params['qft'] = 'filterui:age-lt%s' % time_map[params['time_range']]
query_params['qft'] += f"+filterui:age-lt{time_map[params['time_range']]}"
if params['license_filter']:
query_params['qft'] += f"+filterui:license-{license_map[params['license_filter']]}"
params['url'] = base_url + '?' + urlencode(query_params)

View file

@ -45,6 +45,7 @@ safesearch_cookies = {0: '-2', 1: None, 2: '1'}
safesearch_args = {0: '1', 1: None, 2: '1'}
search_path_map = {'images': 'i', 'videos': 'v', 'news': 'news'}
license_map = {'public': 'Public', 'freetouse': 'Modify', 'commercial': ''}
def request(query, params):
@ -59,12 +60,16 @@ def request(query, params):
eng_region = traits.get_region(params['searxng_locale'], traits.all_locale)
eng_lang = get_ddg_lang(traits, params['searxng_locale'])
f_arg = ''
if ddg_category == 'images' and params['license_filter']:
f_arg = 'license:' + license_map[params['license_filter']]
args = {
'q': query,
'o': 'json',
# 'u': 'bing',
'l': eng_region,
'f': ',,,,,',
'f': ',,,,,' + f_arg,
'vqd': vqd,
}

View file

@ -48,10 +48,12 @@ categories = ['images', 'web']
paging = True
max_page = 50
time_range_support = True
license_filter_support = True
safesearch = True
send_accept_language_header = True
filter_mapping = {0: 'images', 1: 'active', 2: 'active'}
license_map = {'public': 'cl', 'freetouse': 'cl', 'commercial': 'ol'}
def request(query, params):
@ -70,8 +72,14 @@ def request(query, params):
+ f'&async=_fmt:json,p:1,ijn:{params["pageno"] - 1}'
)
tbs_args = []
if params['time_range'] in time_range_dict:
query_url += '&' + urlencode({'tbs': 'qdr:' + time_range_dict[params['time_range']]})
tbs_args.append('qdr:' + time_range_dict[params['time_range']])
if params['license_filter']:
tbs_args.append('sur:' + license_map[params['license_filter']])
if tbs_args:
query_url += '&' + urlencode({'tbs': ','.join(tbs_args)})
if params['safesearch']:
query_url += '&' + urlencode({'safe': filter_mapping[params['safesearch']]})
params['url'] = query_url