mirror of
https://github.com/searxng/searxng.git
synced 2026-09-11 16:56:05 +00:00
[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).
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"Result",
|
"Result",
|
||||||
"MainResult",
|
"MainResult",
|
||||||
|
"LegacyResult",
|
||||||
"KeyValue",
|
"KeyValue",
|
||||||
"EngineResults",
|
"EngineResults",
|
||||||
"AnswerSet",
|
"AnswerSet",
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ from collections.abc import Callable
|
|||||||
import msgspec
|
import msgspec
|
||||||
|
|
||||||
from searx import logger
|
from searx import logger
|
||||||
|
from searx.utils import get_embedded_stream_url
|
||||||
|
|
||||||
log = logger.getChild("result_types")
|
log = logger.getChild("result_types")
|
||||||
|
|
||||||
@@ -480,6 +481,7 @@ class LegacyResult(dict[str, t.Any]):
|
|||||||
category: str
|
category: str
|
||||||
publishedDate: datetime.datetime | None
|
publishedDate: datetime.datetime | None
|
||||||
pubdate: str = ""
|
pubdate: str = ""
|
||||||
|
iframe_src: str | None
|
||||||
|
|
||||||
# infobox result
|
# infobox result
|
||||||
urls: list[dict[str, str]]
|
urls: list[dict[str, str]]
|
||||||
@@ -509,6 +511,7 @@ class LegacyResult(dict[str, t.Any]):
|
|||||||
self["score"] = self.get("score", 0)
|
self["score"] = self.get("score", 0)
|
||||||
self["category"] = self.get("category", "")
|
self["category"] = self.get("category", "")
|
||||||
self["publishedDate"] = self.get("publishedDate")
|
self["publishedDate"] = self.get("publishedDate")
|
||||||
|
self["iframe_src"] = self.get("iframe_src")
|
||||||
|
|
||||||
if "infobox" in self:
|
if "infobox" in self:
|
||||||
self["urls"] = self.get("urls", [])
|
self["urls"] = self.get("urls", [])
|
||||||
@@ -531,6 +534,10 @@ class LegacyResult(dict[str, t.Any]):
|
|||||||
DeprecationWarning,
|
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:
|
def __getattr__(self, name: str, default: t.Any = UNSET) -> t.Any:
|
||||||
if default == UNSET and name not in self:
|
if default == UNSET and name not in self:
|
||||||
raise AttributeError(f"LegacyResult object has no field named: {name}")
|
raise AttributeError(f"LegacyResult object has no field named: {name}")
|
||||||
|
|||||||
@@ -592,7 +592,7 @@ def eval_xpath_getindex(
|
|||||||
return default
|
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,
|
Converts a standard video URL into its embed format. Supported services include Youtube,
|
||||||
Facebook, Instagram, TikTok, Dailymotion, and Bilibili.
|
Facebook, Instagram, TikTok, Dailymotion, and Bilibili.
|
||||||
|
|||||||
Reference in New Issue
Block a user