diff options
| author | Bnyro <bnyro@tutanota.com> | 2026-07-29 17:56:20 +0200 |
|---|---|---|
| committer | Bnyro <bnyro@tutanota.com> | 2026-09-03 17:28:29 +0200 |
| commit | a1144dda3e97668c9d445022b7019c224cd4bb1e (patch) | |
| tree | 151b901ce7ada06ce75e17fecf8d7944f0c142da | |
| parent | 86008c9dd609fb8e6e85699238ed50e9045c913a (diff) | |
[mod] engines: migrate video engines away from get_embedded_stream_url
| -rw-r--r-- | searx/engines/360search_videos.py | 28 | ||||
| -rw-r--r-- | searx/engines/brave.py | 7 | ||||
| -rw-r--r-- | searx/engines/duckduckgo_extra.py | 68 | ||||
| -rw-r--r-- | searx/engines/google_videos.py | 2 | ||||
| -rw-r--r-- | searx/engines/naver.py | 22 | ||||
| -rw-r--r-- | searx/engines/privacywall.py | 3 | ||||
| -rw-r--r-- | searx/engines/qwant.py | 4 | ||||
| -rw-r--r-- | searx/engines/tonline.py | 3 |
8 files changed, 61 insertions, 76 deletions
diff --git a/searx/engines/360search_videos.py b/searx/engines/360search_videos.py index 27b3781b4..d359d534f 100644 --- a/searx/engines/360search_videos.py +++ b/searx/engines/360search_videos.py @@ -6,7 +6,8 @@ from urllib.parse import urlencode from datetime import datetime from searx.exceptions import SearxEngineAPIException -from searx.utils import html_to_text, get_embeded_stream_url +from searx.result_types import EngineResults +from searx.utils import html_to_text about = { "website": "https://tv.360kan.com/", @@ -29,12 +30,12 @@ def request(query, params): return params -def response(resp): +def response(resp) -> EngineResults: try: data = resp.json() except Exception as e: raise SearxEngineAPIException(f"Invalid response: {e}") from e - results = [] + res = EngineResults() if "data" not in data or "result" not in data["data"]: raise SearxEngineAPIException("Invalid response") @@ -50,16 +51,15 @@ def response(resp): except (ValueError, TypeError): published_date = None - results.append( - { - 'url': entry["play_url"], - 'title': html_to_text(entry["title"]), - 'content': html_to_text(entry["description"]), - 'template': 'videos.html', - 'publishedDate': published_date, - 'thumbnail': entry["cover_img"], - "iframe_src": get_embeded_stream_url(entry["play_url"]), - } + res.add( + res.types.LegacyResult( + url=entry["play_url"], + title=html_to_text(entry["title"]), + content=html_to_text(entry["description"]), + template='videos.html', + publishedDate=published_date, + thumbnail=entry["cover_img"], + ) ) - return results + return res diff --git a/searx/engines/brave.py b/searx/engines/brave.py index dcc96609f..d20494e17 100644 --- a/searx/engines/brave.py +++ b/searx/engines/brave.py @@ -135,7 +135,7 @@ from searx.utils import ( eval_xpath_getindex, eval_xpath_list, extract_text, - get_embeded_stream_url, + get_embedded_stream_url, js_obj_str_to_json_str, js_obj_str_to_python, ) @@ -338,7 +338,7 @@ def _parse_search(resp: SXNG_Response) -> EngineResults: if len(video_tag): # In my tests a video tag in the WEB search was most often not a # video, except the ones from youtube .. - iframe_src = get_embeded_stream_url(url) + iframe_src = get_embedded_stream_url(url) if iframe_src: item["iframe_src"] = iframe_src item["template"] = "videos.html" @@ -406,9 +406,6 @@ def _parse_videos(json_resp: dict[str, t.Any]) -> EngineResults: ) if result["thumbnail"] is not None: item["thumbnail"] = result["thumbnail"]["src"] - iframe_src = get_embeded_stream_url(result["url"]) - if iframe_src: - item["iframe_src"] = iframe_src res.add(item) diff --git a/searx/engines/duckduckgo_extra.py b/searx/engines/duckduckgo_extra.py index e3042183e..194b5deb9 100644 --- a/searx/engines/duckduckgo_extra.py +++ b/searx/engines/duckduckgo_extra.py @@ -10,7 +10,8 @@ from datetime import datetime from urllib.parse import urlencode from urllib.parse import quote_plus -from searx.utils import get_embeded_stream_url, html_to_text, gen_useragent, extr +from searx.result_types import EngineResults, MainResult, LegacyResult, Image +from searx.utils import html_to_text, gen_useragent, extr from searx.network import get # see https://github.com/searxng/searxng/issues/762 from searx.engines.duckduckgo import fetch_traits # pylint: disable=unused-import @@ -148,54 +149,51 @@ def request(query: str, params: "OnlineParams") -> None: def _image_result(result): - return { - 'template': 'images.html', - 'url': result['url'], - 'title': result['title'], - 'content': '', - 'thumbnail_src': result['thumbnail'], - 'img_src': result['image'], - 'resolution': '%s x %s' % (result['width'], result['height']), - 'source': result['source'], - } + return Image( + url=result['url'], + title=result['title'], + content='', + thumbnail_src=result['thumbnail'], + img_src=result['image'], + resolution='%s x %s' % (result['width'], result['height']), + source=result['source'], + ) def _video_result(result): - return { - 'template': 'videos.html', - 'url': result['content'], - 'title': result['title'], - 'content': result['description'], - 'thumbnail': result['images'].get('small') or result['images'].get('medium'), - 'iframe_src': get_embeded_stream_url(result['content']), - 'source': result['provider'], - 'length': result['duration'], - 'metadata': result.get('uploader'), - } + return LegacyResult( + template='videos.html', + url=result['content'], + title=result['title'], + content=result['description'], + thumbnail=result['images'].get('small') or result['images'].get('medium'), + source=result['provider'], + length=result['duration'], + metadata=result.get('uploader'), + ) def _news_result(result): - return { - 'url': result['url'], - 'title': result['title'], - 'content': html_to_text(result['excerpt']), - 'source': result['source'], - 'publishedDate': datetime.fromtimestamp(result['date']), - } + return MainResult( + url=result['url'], + title=result['title'], + content=html_to_text(result['excerpt']), + publishedDate=datetime.fromtimestamp(result['date']), + ) -def response(resp): - results = [] +def response(resp: "SXNG_Response") -> EngineResults: + res = EngineResults() res_json = resp.json() for result in res_json['results']: if ddg_category == 'images': - results.append(_image_result(result)) + res.add(_image_result(result)) elif ddg_category == 'videos': - results.append(_video_result(result)) + res.add(_video_result(result)) elif ddg_category == 'news': - results.append(_news_result(result)) + res.add(_news_result(result)) else: raise ValueError(f"Invalid duckduckgo category: {ddg_category}") - return results + return res diff --git a/searx/engines/google_videos.py b/searx/engines/google_videos.py index 6a30223be..a0a72fc12 100644 --- a/searx/engines/google_videos.py +++ b/searx/engines/google_videos.py @@ -10,7 +10,6 @@ from searx.utils import ( eval_xpath_getindex, eval_xpath_list, extract_text, - get_embeded_stream_url, parse_duration_string, ) @@ -79,7 +78,6 @@ def response(resp: "SXNG_Response") -> EngineResults: title=title, thumbnail=thumbnail, length=length, - iframe_src=get_embeded_stream_url(url) or "", template="videos.html", ) ) diff --git a/searx/engines/naver.py b/searx/engines/naver.py index ca0123095..fe438b9f4 100644 --- a/searx/engines/naver.py +++ b/searx/engines/naver.py @@ -18,7 +18,6 @@ from searx.utils import ( html_to_text, parse_duration_string, js_obj_str_to_python, - get_embeded_stream_url, ) # engine metadata @@ -195,7 +194,7 @@ def parse_news(data): def parse_videos(data): - results = [] + res = EngineResults() dom = html.fromstring(data) @@ -214,15 +213,14 @@ def parse_videos(data): except (ValueError, TypeError): pass - results.append( - { - "template": "videos.html", - "title": extract_text(eval_xpath(item, ".//a[contains(@class, 'info_title')]")), - "url": url, - "thumbnail": thumbnail, - "length": length, - "iframe_src": get_embeded_stream_url(url), - } + res.add( + res.types.LegacyResult( + template="videos.html", + title=extract_text(eval_xpath(item, ".//a[contains(@class, 'info_title')]")), + url=url, + thumbnail=thumbnail, + length=length, + ) ) - return results + return res diff --git a/searx/engines/privacywall.py b/searx/engines/privacywall.py index 2dde35b2d..4d8cac4ac 100644 --- a/searx/engines/privacywall.py +++ b/searx/engines/privacywall.py @@ -14,7 +14,7 @@ from lxml import html import babel from searx.enginelib.traits import EngineTraits -from searx.utils import eval_xpath_list, eval_xpath, extract_text, get_embeded_stream_url, extr +from searx.utils import eval_xpath_list, eval_xpath, extract_text, extr from searx.locales import region_tag from searx.result_types import EngineResults @@ -154,7 +154,6 @@ def _video_results(doc: "ElementBase") -> EngineResults: title=extract_text(eval_xpath(result, ".//h2[contains(@class, 'video-card-title')]")) or "", content=extract_text(eval_xpath(result, ".//p")) or "", thumbnail=thumbnail or "", - iframe_src=get_embeded_stream_url(url) or "", ) ) diff --git a/searx/engines/qwant.py b/searx/engines/qwant.py index 1a7bbc28d..182394777 100644 --- a/searx/engines/qwant.py +++ b/searx/engines/qwant.py @@ -60,9 +60,6 @@ from searx.exceptions import ( SearxEngineTooManyRequestsException, ) from searx.network import raise_for_httperror -from searx.utils import ( - get_embeded_stream_url, -) from searx.result_types import EngineResults if t.TYPE_CHECKING: @@ -299,7 +296,6 @@ def response(resp: "SXNG_Response") -> EngineResults: title=title, url=res_url, content=content, - iframe_src=get_embeded_stream_url(res_url), publishedDate=pub_date, thumbnail=thumbnail, template="videos.html", diff --git a/searx/engines/tonline.py b/searx/engines/tonline.py index 04fb34250..4edf5e3ed 100644 --- a/searx/engines/tonline.py +++ b/searx/engines/tonline.py @@ -14,7 +14,7 @@ from urllib.parse import urlencode from lxml import html -from searx.utils import eval_xpath_list, eval_xpath, extract_text, get_embeded_stream_url, ElementType +from searx.utils import eval_xpath_list, eval_xpath, extract_text, ElementType from searx.result_types import EngineResults from searx.enginelib import EngineAbout @@ -126,7 +126,6 @@ def _video_results(doc: ElementType, res: EngineResults): url=url, title=" - ".join(extract_text(part) or "" for part in title_parts), thumbnail=extract_text(eval_xpath(result, ".//img/@src") or "") or "", - iframe_src=get_embeded_stream_url(url) or "", ) ) |
