[mod] fireball: small fixup from code review (#6240)

Co-authored-by: Markus Heiser <markus.heiser@darmarIT.de>
This commit is contained in:
Bnyro
2026-06-11 12:09:57 +02:00
committed by GitHub
parent 3a382cb3f3
commit a1490676e3
+16 -23
View File
@@ -1,7 +1,8 @@
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
"""Fireball_ is a Germany-based, privacy-focused search engine. """Fireball_ is a Germany-based, privacy-focused search engine.
It likely doesn't have its own index, but it's unclear where its results come from. It likely doesn't have its own index, but it's unclear where its results come
from.
.. _Fireball: https://fireball.com .. _Fireball: https://fireball.com
""" """
@@ -46,15 +47,12 @@ CACHE_VALID_DURATION = 30 * 24 * 3600 # one month, same as website
"""Duration how long settings cookies are valid.""" """Duration how long settings cookies are valid."""
def init(_): def init(engine_settings: dict[str, t.Any]):
if fireball_category not in ("web", "news", "videos"):
raise ValueError(f"Unsupported category: {fireball_category}")
def setup(engine_settings: dict[str, t.Any]) -> bool:
global CACHE # pylint: disable=global-statement global CACHE # pylint: disable=global-statement
CACHE = EngineCache(engine_settings["name"]) CACHE = EngineCache(engine_settings["name"])
return True
if fireball_category not in ("web", "news", "videos"):
raise ValueError(f"Unsupported category: {fireball_category}")
def _cache_key(fireball_settings: dict[str, str]) -> str: def _cache_key(fireball_settings: dict[str, str]) -> str:
@@ -62,13 +60,12 @@ def _cache_key(fireball_settings: dict[str, str]) -> str:
def _get_search_settings_cookie(params: 'OnlineParams') -> str: def _get_search_settings_cookie(params: 'OnlineParams') -> str:
""" """Get a 'fireball' cookie for the given locale and safesearch setting set
Get a 'fireball' cookie for the given locale and safesearch setting set in params. in params."""
"""
# the language is set by only specifying the search country # the language is set by only specifying the search country on their
# on their website, they only list DE and US, but in fact it # website, they only list DE and US, but in fact it supports much more
# supports much more countries # countries
country = "US" country = "US"
if params["searxng_locale"] != "all": if params["searxng_locale"] != "all":
language_parts = params["searxng_locale"].split("-") language_parts = params["searxng_locale"].split("-")
@@ -101,9 +98,9 @@ def _get_search_settings_cookie(params: 'OnlineParams') -> str:
return cookie return cookie
def request(query: str, params: 'OnlineParams'): def request(query: str, params: "OnlineParams"):
# no matter the category, the request is always the same # no matter the category, the request is always the same, i.e. we get all
# i.e. we get all different categories with one HTTP request # different categories with one HTTP request
args = { args = {
"f": "web", "f": "web",
@@ -117,7 +114,7 @@ def request(query: str, params: 'OnlineParams'):
params["headers"]["Referer"] = f"{base_url}/search?{urlencode(args)}" params["headers"]["Referer"] = f"{base_url}/search?{urlencode(args)}"
def response(resp: 'SXNG_Response') -> EngineResults: def response(resp: "SXNG_Response") -> EngineResults:
res = EngineResults() res = EngineResults()
json_data = resp.json() json_data = resp.json()
@@ -151,10 +148,6 @@ def response(resp: 'SXNG_Response') -> EngineResults:
) )
) )
elif fireball_category == "videos": elif fireball_category == "videos":
thumbnail = None
if result.get("thumbnail"):
thumbnail = result["thumbnail"]["original"]
length = None length = None
if result.get("video"): if result.get("video"):
length = result["video"].get("duration") length = result["video"].get("duration")
@@ -166,7 +159,7 @@ def response(resp: 'SXNG_Response') -> EngineResults:
"url": result["url"], "url": result["url"],
"title": html_to_text(result["title"]), "title": html_to_text(result["title"]),
"content": html_to_text(result["description"]), "content": html_to_text(result["description"]),
"thumbnail": thumbnail, "thumbnail": result.get("thumbnail", {}).get("original"),
"length": length, "length": length,
"publishedDate": published_date, "publishedDate": published_date,
} }