From 808dcaf1e2086177e12aeca097d2e851c72e0471 Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Sun, 13 Apr 2025 18:47:25 +0800 Subject: [PATCH] [feat] engine: add Steam engine --- searx/engines/steam.py | 51 ++++++++++++++++++++++++++++++++++++++++++ searx/settings.yml | 5 +++++ 2 files changed, 56 insertions(+) create mode 100644 searx/engines/steam.py diff --git a/searx/engines/steam.py b/searx/engines/steam.py new file mode 100644 index 000000000..f25516e00 --- /dev/null +++ b/searx/engines/steam.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +"""Steam (store) for SearXNG.""" + +from urllib.parse import urlencode + +from searx.utils import html_to_text +from searx.result_types import EngineResults, MainResult + +about = { + "website": 'https://store.steampowered.com/', + "wikidata_id": 'Q337535', + "use_official_api": False, + "require_api_key": False, + "results": 'JSON', +} + +categories = [] + +base_url = "https://store.steampowered.com" + + +def request(query, params): + query_params = {"term": query, "cc": "us", "l": "en"} + params['url'] = f'{base_url}/api/storesearch/?{urlencode(query_params)}' + return params + + +def response(resp) -> EngineResults: + results = EngineResults() + search_results = resp.json() + + for item in search_results.get('items', []): + app_id = item.get('id') + + currency = item.get('price', {}).get('currency', 'USD') + price = item.get('price', {}).get('final', 0) / 100 + + platforms = ', '.join([platform for platform, supported in item.get('platforms', {}).items() if supported]) + + content = [f'Price: {price:.2f} {currency}', f'Platforms: {platforms}'] + + results.add( + MainResult( + title=item.get('name'), + content=html_to_text(' | '.join(content)), + url=f'{base_url}/app/{app_id}', + thumbnail=item.get('tiny_image', ''), + ) + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 714921731..e3201e8ca 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -1971,6 +1971,11 @@ engines: categories: [images, web] shortcut: spi + - name: steam + engine: steam + shortcut: stm + disabled: true + - name: tokyotoshokan engine: tokyotoshokan shortcut: tt