summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2026-06-16 21:49:56 +0200
committerBnyro <bnyro@tutanota.com>2026-06-29 10:02:16 +0200
commit0fd40d5f2948f158047450ba4b27e0a7a5e2a9f0 (patch)
tree1b4f013b23d948d12f1a1cdd4944b6dfd3935e0f /searx/engines
parent13a5ace8b54d8300eaf1f276ddb325270b389110 (diff)
[feat] engines: add shopify stock images engine
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/shopify_stock.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/searx/engines/shopify_stock.py b/searx/engines/shopify_stock.py
new file mode 100644
index 000000000..a511d92e7
--- /dev/null
+++ b/searx/engines/shopify_stock.py
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+"""Shopify stock photos provides royalty-free images, intended for use with
+Shopify.
+"""
+
+import typing as t
+from urllib.parse import urlencode
+
+from lxml import html
+
+from searx.result_types import EngineResults
+from searx.utils import eval_xpath, eval_xpath_list, extract_text
+
+if t.TYPE_CHECKING:
+ from searx.extended_types import SXNG_Response
+ from searx.search.processors import OnlineParams
+
+
+about = {
+ "website": "https://www.shopify.com/stock-photos",
+ "wikidata_id": None,
+ "official_api_documentation": None,
+ "use_official_api": False,
+ "require_api_key": False,
+ "results": "HTML",
+}
+
+base_url = "https://www.shopify.com"
+
+categories = ["images"]
+paging = True
+
+
+def request(query: str, params: "OnlineParams") -> None:
+ args = {"q": query, "page": params["pageno"]}
+ params["url"] = f"{base_url}/stock-photos/photos/search?{urlencode(args)}"
+
+
+def _get_download_url(url: str) -> str:
+ """Get the link to the full quality image."""
+ query_start = url.find("?")
+ return url[:query_start] + "/download?quality=premium"
+
+
+def response(resp: "SXNG_Response"):
+ res = EngineResults()
+
+ doc = html.fromstring(resp.text)
+
+ for result in eval_xpath_list(doc, "//div[contains(@class, 'js-masonry-grid')]/div"):
+ url = base_url + (extract_text(eval_xpath(result, ".//a[contains(@class, 'photo-tile')]/@href")) or "")
+ res.add(
+ res.types.Image(
+ url=url,
+ title=extract_text(eval_xpath(result, ".//p[contains(@class, 'photo-tile__title')]")) or "",
+ thumbnail_src=extract_text(eval_xpath(result, ".//img[contains(@class, 'photo-card__image')]/@src"))
+ or "",
+ img_src=_get_download_url(url),
+ )
+ )
+
+ return res