diff options
| author | Bnyro <bnyro@tutanota.com> | 2026-07-29 17:55:53 +0200 |
|---|---|---|
| committer | Bnyro <bnyro@tutanota.com> | 2026-09-03 17:28:29 +0200 |
| commit | 86008c9dd609fb8e6e85699238ed50e9045c913a (patch) | |
| tree | 558a3c7b3dce232362f3ea2a4f525b68e425a007 | |
| parent | 8f452ee89293d9a752a776f4c33f5a5f124fff97 (diff) | |
[feat] results: automatically set embedded stream url for video results
Currently, many engines that provide video results call the same
`get_embedded_stream_url` method for setting the `iframe_src`. There
is no value in that because this logic is engine-specific and probably
many video engines forgot to implement this.
With these changes, it's done automatically, so engine implementors
don't have to worry about setting an `iframe_src` (unless the engine
explicitly has a field for it).
| -rw-r--r-- | searx/result_types/__init__.py | 1 | ||||
| -rw-r--r-- | searx/result_types/_base.py | 7 | ||||
| -rw-r--r-- | searx/utils.py | 2 |
3 files changed, 9 insertions, 1 deletions
diff --git a/searx/result_types/__init__.py b/searx/result_types/__init__.py index 2ea989149..5a2ae6f47 100644 --- a/searx/result_types/__init__.py +++ b/searx/result_types/__init__.py @@ -15,6 +15,7 @@ __all__ = [ "Result", "MainResult", + "LegacyResult", "KeyValue", "EngineResults", "AnswerSet", diff --git a/searx/result_types/_base.py b/searx/result_types/_base.py index 94a55337c..9284302e3 100644 --- a/searx/result_types/_base.py +++ b/searx/result_types/_base.py @@ -31,6 +31,7 @@ from collections.abc import Callable import msgspec from searx import logger +from searx.utils import get_embedded_stream_url log = logger.getChild("result_types") @@ -480,6 +481,7 @@ class LegacyResult(dict[str, t.Any]): category: str publishedDate: datetime.datetime | None pubdate: str = "" + iframe_src: str | None # infobox result urls: list[dict[str, str]] @@ -509,6 +511,7 @@ class LegacyResult(dict[str, t.Any]): self["score"] = self.get("score", 0) self["category"] = self.get("category", "") self["publishedDate"] = self.get("publishedDate") + self["iframe_src"] = self.get("iframe_src") if "infobox" in self: self["urls"] = self.get("urls", []) @@ -531,6 +534,10 @@ class LegacyResult(dict[str, t.Any]): DeprecationWarning, ) + # TODO: move into typed video results class once it is implemented # pylint: disable=fixme + if self.template == "videos.html" and self.url and not self.iframe_src: + self.iframe_src = get_embedded_stream_url(self.url) + def __getattr__(self, name: str, default: t.Any = UNSET) -> t.Any: if default == UNSET and name not in self: raise AttributeError(f"LegacyResult object has no field named: {name}") diff --git a/searx/utils.py b/searx/utils.py index 1ebfda12f..9c70c8cc4 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -592,7 +592,7 @@ def eval_xpath_getindex( return default -def get_embeded_stream_url(url: str): +def get_embedded_stream_url(url: str): """ Converts a standard video URL into its embed format. Supported services include Youtube, Facebook, Instagram, TikTok, Dailymotion, and Bilibili. |
