mirror of
https://github.com/searxng/searxng.git
synced 2026-06-14 22:06:52 +02:00
e3bd7f5df1
* [mod] template images.html: reformatted for readability (no func change) In preparation for upcoming changes, the template is being reformatted for better readability; no functional changes are being made. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de> * [mod] image results: add list of alternative formats To test alternatives formats apply patch from below, query ``!flaticon bmw`` and open the detail view for the image. diff --git a/searx/engines/flaticon.py b/searx/engines/flaticon.py index 06b6a8e25..d88388705 100644 --- a/searx/engines/flaticon.py +++ b/searx/engines/flaticon.py @@ -8,7 +8,7 @@ from urllib.parse import urlencode import typing as t -from searx.result_types import EngineResults +from searx.result_types import EngineResults, ImageRef if t.TYPE_CHECKING: from searx.extended_types import SXNG_Response @@ -61,6 +61,14 @@ def response(resp: "SXNG_Response"): thumbnail_src=_fix_url(result["png"]), img_src=_fix_url(result["png512"]), author=result["team_name"], + formats=[ + ImageRef(label="PNG 100x100", url="https://example.org/test.png", subtype="png"), + ImageRef(label="SVG", url="https://example.org/test.svg", subtype="svg+xml"), + ImageRef(url="https://example.org/test.jpg", subtype="jpeg"), + ImageRef(url="https://example.org/test.bmp", subtype="bmp"), + ImageRef(url="https://example.org/test.ico", subtype="x-icon"), + ImageRef(url="https://example.org/test.tif", subtype="tiff"), + ], ) ) Signed-off-by: Markus Heiser <markus.heiser@darmarit.de> --------- Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""Flaticon_ is a database for icons.
|
|
|
|
.. _Flaticon: https://www.flaticon.com
|
|
"""
|
|
|
|
from urllib.parse import urlencode
|
|
|
|
import typing as t
|
|
|
|
from searx.result_types import EngineResults
|
|
|
|
if t.TYPE_CHECKING:
|
|
from searx.extended_types import SXNG_Response
|
|
from searx.search.processors import OnlineParams
|
|
|
|
|
|
about = {
|
|
"website": "https://www.flaticon.com",
|
|
"wikidata_id": "Q105283791",
|
|
"official_api_documentation": None,
|
|
"use_official_api": False,
|
|
"require_api_key": False,
|
|
"results": "JSON",
|
|
}
|
|
|
|
base_url = "https://www.flaticon.com"
|
|
|
|
categories = ["images", "icons"]
|
|
paging = True
|
|
|
|
|
|
def request(query: str, params: "OnlineParams") -> None:
|
|
args = {
|
|
"word": query,
|
|
}
|
|
params["headers"].update(
|
|
{
|
|
# important: query term is not URL encoded in the referer string
|
|
"Referer": f"{base_url}/search?word={query}",
|
|
"X-Requested-With": "XMLHttpRequest",
|
|
}
|
|
)
|
|
params["url"] = f"{base_url}/ajax/search/{params['pageno']}?{urlencode(args)}"
|
|
|
|
|
|
def _fix_url(url: str) -> str:
|
|
return url.replace(r"\/", "/")
|
|
|
|
|
|
def response(resp: "SXNG_Response"):
|
|
res = EngineResults()
|
|
|
|
result: dict[str, str] # TBH: dict[str, t.Any]
|
|
for result in resp.json()["items"]:
|
|
tags = [
|
|
tag_info["tag"] for tag_info in result["tags"] if tag_info["tag"] # pyright: ignore[reportArgumentType]
|
|
]
|
|
res.add(
|
|
res.types.Image(
|
|
title=result["name"],
|
|
content=", ".join(tags),
|
|
url=_fix_url(result["slug"]),
|
|
thumbnail_src=_fix_url(result["png"]),
|
|
img_src=_fix_url(result["png512"]),
|
|
img_format="PNG",
|
|
author=result["team_name"],
|
|
)
|
|
)
|
|
|
|
return res
|