mirror of
https://github.com/searxng/searxng.git
synced 2024-05-12 08:32:39 +00:00
Compare commits
3 commits
52a49edab5
...
d55e303055
Author | SHA1 | Date | |
---|---|---|---|
d55e303055 | |||
ecee56533c | |||
f02d9b523d |
|
@ -3,6 +3,8 @@
|
|||
|
||||
"""
|
||||
|
||||
import datetime
|
||||
|
||||
from urllib.parse import urlencode
|
||||
|
||||
# about
|
||||
|
@ -14,6 +16,8 @@ about = {
|
|||
"require_api_key": False,
|
||||
"results": 'JSON',
|
||||
}
|
||||
categories = ['images']
|
||||
search_type = 'images'
|
||||
|
||||
base_url = "https://commons.wikimedia.org"
|
||||
search_prefix = (
|
||||
|
@ -29,17 +33,29 @@ search_prefix = (
|
|||
paging = True
|
||||
number_of_results = 10
|
||||
|
||||
search_types = {
|
||||
'images': 'bitmap|drawing',
|
||||
'videos': 'video',
|
||||
'audio': 'audio',
|
||||
'files': 'multimedia|office|archive|3d',
|
||||
}
|
||||
|
||||
|
||||
def request(query, params):
|
||||
language = 'en'
|
||||
if params['language'] != 'all':
|
||||
language = params['language'].split('-')[0]
|
||||
|
||||
if search_type not in search_types:
|
||||
raise ValueError(f"Unsupported search type: {search_type}")
|
||||
|
||||
filetype = search_types[search_type]
|
||||
|
||||
args = {
|
||||
'uselang': language,
|
||||
'gsrlimit': number_of_results,
|
||||
'gsroffset': number_of_results * (params["pageno"] - 1),
|
||||
'gsrsearch': "filetype:bitmap|drawing " + query,
|
||||
'gsrsearch': f"filetype:{filetype} {query}",
|
||||
}
|
||||
|
||||
params["url"] = f"{base_url}/w/api.php{search_prefix}&{urlencode(args, safe=':|')}"
|
||||
|
@ -52,7 +68,6 @@ def response(resp):
|
|||
|
||||
if not json.get("query", {}).get("pages"):
|
||||
return results
|
||||
|
||||
for item in json["query"]["pages"].values():
|
||||
imageinfo = item["imageinfo"][0]
|
||||
title = item["title"].replace("File:", "").rsplit('.', 1)[0]
|
||||
|
@ -60,11 +75,28 @@ def response(resp):
|
|||
'url': imageinfo["descriptionurl"],
|
||||
'title': title,
|
||||
'content': item["snippet"],
|
||||
'img_src': imageinfo["url"],
|
||||
'resolution': f'{imageinfo["width"]} x {imageinfo["height"]}',
|
||||
'thumbnail_src': imageinfo["thumburl"],
|
||||
'template': 'images.html',
|
||||
}
|
||||
|
||||
if search_type == "images":
|
||||
result['template'] = 'images.html'
|
||||
result['img_src'] = imageinfo["url"]
|
||||
result['thumbnail_src'] = imageinfo["thumburl"]
|
||||
result['resolution'] = f'{imageinfo["width"]} x {imageinfo["height"]}'
|
||||
else:
|
||||
result['thumbnail'] = imageinfo["thumburl"]
|
||||
|
||||
if search_type == "videos":
|
||||
result['template'] = 'videos.html'
|
||||
if imageinfo.get('duration'):
|
||||
result['length'] = datetime.timedelta(seconds=int(imageinfo['duration']))
|
||||
result['iframe_src'] = imageinfo['url']
|
||||
elif search_type == "files":
|
||||
result['template'] = 'files.html'
|
||||
result['metadata'] = imageinfo['mime']
|
||||
result['size'] = imageinfo['size']
|
||||
elif search_type == "audio":
|
||||
result['iframe_src'] = imageinfo['url']
|
||||
|
||||
results.append(result)
|
||||
|
||||
return results
|
||||
|
|
|
@ -1888,6 +1888,28 @@ engines:
|
|||
engine: wikicommons
|
||||
shortcut: wc
|
||||
categories: images
|
||||
search_type: images
|
||||
number_of_results: 10
|
||||
|
||||
- name: wikicommons.videos
|
||||
engine: wikicommons
|
||||
shortcut: wcv
|
||||
categories: videos
|
||||
search_type: videos
|
||||
number_of_results: 10
|
||||
|
||||
- name: wikicommons.audio
|
||||
engine: wikicommons
|
||||
shortcut: wca
|
||||
categories: music
|
||||
search_type: audio
|
||||
number_of_results: 10
|
||||
|
||||
- name: wikicommons.files
|
||||
engine: wikicommons
|
||||
shortcut: wcf
|
||||
categories: files
|
||||
search_type: files
|
||||
number_of_results: 10
|
||||
|
||||
- name: wolframalpha
|
||||
|
|
|
@ -63,7 +63,7 @@ or manually by executing the searx/webapp.py file? -->
|
|||
<input type="checkbox" id="step1">
|
||||
<label for="step1">{{ _('Start submiting a new issue on GitHub') }}</label>
|
||||
<div class="step1 step_content">
|
||||
<p><a href="{{ get_setting('brand.issue_url') }}?q=is%3Aissue+Bug:%20{{ engine_name }}" target="_blank" rel="noreferrer noreferrer">{{ _('Please check for existing bugs about this engine on GitHub') }}</a></p>
|
||||
<p><a href="{{ get_setting('brand.issue_url') }}?q=is%3Aissue+Bug:%20{{ engine_name }} {{ technical_report }}" target="_blank" rel="noreferrer noreferrer">{{ _('Please check for existing bugs about this engine on GitHub') }}</a></p>
|
||||
</div>
|
||||
<input class="step1 step1_delay" type="checkbox" id="step2">
|
||||
<label class="step1 step1_delay" for="step2" >{{ _('I confirm there is no existing bug about the issue I encounter') }}</label>
|
||||
|
|
|
@ -1161,6 +1161,21 @@ def stats():
|
|||
reliability_order = 1 - reliability_order
|
||||
return (reliability_order, key, engine_stat['name'])
|
||||
|
||||
technical_report = []
|
||||
for error in engine_reliabilities.get(selected_engine_name, {}).get('errors', []):
|
||||
technical_report.append(
|
||||
f"\
|
||||
Error: {error['exception_classname'] or error['log_message']} \
|
||||
Parameters: {error['log_parameters']} \
|
||||
File name: {error['filename'] }:{ error['line_no'] } \
|
||||
Error Function: {error['function']} \
|
||||
Code: {error['code']} \
|
||||
".replace(
|
||||
' ' * 12, ''
|
||||
).strip()
|
||||
)
|
||||
technical_report = ' '.join(technical_report)
|
||||
|
||||
engine_stats['time'] = sorted(engine_stats['time'], reverse=reverse, key=get_key)
|
||||
return render(
|
||||
# fmt: off
|
||||
|
@ -1170,6 +1185,7 @@ def stats():
|
|||
engine_reliabilities = engine_reliabilities,
|
||||
selected_engine_name = selected_engine_name,
|
||||
searx_git_branch = GIT_BRANCH,
|
||||
technical_report = technical_report,
|
||||
# fmt: on
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue