[mod] engines: migrate video engines away from get_embedded_stream_url

This commit is contained in:
Bnyro
2026-07-29 17:56:20 +02:00
parent 86008c9dd6
commit a1144dda3e
8 changed files with 61 additions and 76 deletions

View File

@@ -6,7 +6,8 @@ from urllib.parse import urlencode
from datetime import datetime from datetime import datetime
from searx.exceptions import SearxEngineAPIException 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 = { about = {
"website": "https://tv.360kan.com/", "website": "https://tv.360kan.com/",
@@ -29,12 +30,12 @@ def request(query, params):
return params return params
def response(resp): def response(resp) -> EngineResults:
try: try:
data = resp.json() data = resp.json()
except Exception as e: except Exception as e:
raise SearxEngineAPIException(f"Invalid response: {e}") from e raise SearxEngineAPIException(f"Invalid response: {e}") from e
results = [] res = EngineResults()
if "data" not in data or "result" not in data["data"]: if "data" not in data or "result" not in data["data"]:
raise SearxEngineAPIException("Invalid response") raise SearxEngineAPIException("Invalid response")
@@ -50,16 +51,15 @@ def response(resp):
except (ValueError, TypeError): except (ValueError, TypeError):
published_date = None published_date = None
results.append( res.add(
{ res.types.LegacyResult(
'url': entry["play_url"], url=entry["play_url"],
'title': html_to_text(entry["title"]), title=html_to_text(entry["title"]),
'content': html_to_text(entry["description"]), content=html_to_text(entry["description"]),
'template': 'videos.html', template='videos.html',
'publishedDate': published_date, publishedDate=published_date,
'thumbnail': entry["cover_img"], thumbnail=entry["cover_img"],
"iframe_src": get_embeded_stream_url(entry["play_url"]), )
}
) )
return results return res

View File

@@ -135,7 +135,7 @@ from searx.utils import (
eval_xpath_getindex, eval_xpath_getindex,
eval_xpath_list, eval_xpath_list,
extract_text, extract_text,
get_embeded_stream_url, get_embedded_stream_url,
js_obj_str_to_json_str, js_obj_str_to_json_str,
js_obj_str_to_python, js_obj_str_to_python,
) )
@@ -338,7 +338,7 @@ def _parse_search(resp: SXNG_Response) -> EngineResults:
if len(video_tag): if len(video_tag):
# In my tests a video tag in the WEB search was most often not a # In my tests a video tag in the WEB search was most often not a
# video, except the ones from youtube .. # video, except the ones from youtube ..
iframe_src = get_embeded_stream_url(url) iframe_src = get_embedded_stream_url(url)
if iframe_src: if iframe_src:
item["iframe_src"] = iframe_src item["iframe_src"] = iframe_src
item["template"] = "videos.html" item["template"] = "videos.html"
@@ -406,9 +406,6 @@ def _parse_videos(json_resp: dict[str, t.Any]) -> EngineResults:
) )
if result["thumbnail"] is not None: if result["thumbnail"] is not None:
item["thumbnail"] = result["thumbnail"]["src"] item["thumbnail"] = result["thumbnail"]["src"]
iframe_src = get_embeded_stream_url(result["url"])
if iframe_src:
item["iframe_src"] = iframe_src
res.add(item) res.add(item)

View File

@@ -10,7 +10,8 @@ from datetime import datetime
from urllib.parse import urlencode from urllib.parse import urlencode
from urllib.parse import quote_plus 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.network import get # see https://github.com/searxng/searxng/issues/762
from searx.engines.duckduckgo import fetch_traits # pylint: disable=unused-import 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): def _image_result(result):
return { return Image(
'template': 'images.html', url=result['url'],
'url': result['url'], title=result['title'],
'title': result['title'], content='',
'content': '', thumbnail_src=result['thumbnail'],
'thumbnail_src': result['thumbnail'], img_src=result['image'],
'img_src': result['image'], resolution='%s x %s' % (result['width'], result['height']),
'resolution': '%s x %s' % (result['width'], result['height']), source=result['source'],
'source': result['source'], )
}
def _video_result(result): def _video_result(result):
return { return LegacyResult(
'template': 'videos.html', template='videos.html',
'url': result['content'], url=result['content'],
'title': result['title'], title=result['title'],
'content': result['description'], content=result['description'],
'thumbnail': result['images'].get('small') or result['images'].get('medium'), thumbnail=result['images'].get('small') or result['images'].get('medium'),
'iframe_src': get_embeded_stream_url(result['content']), source=result['provider'],
'source': result['provider'], length=result['duration'],
'length': result['duration'], metadata=result.get('uploader'),
'metadata': result.get('uploader'), )
}
def _news_result(result): def _news_result(result):
return { return MainResult(
'url': result['url'], url=result['url'],
'title': result['title'], title=result['title'],
'content': html_to_text(result['excerpt']), content=html_to_text(result['excerpt']),
'source': result['source'], publishedDate=datetime.fromtimestamp(result['date']),
'publishedDate': datetime.fromtimestamp(result['date']), )
}
def response(resp): def response(resp: "SXNG_Response") -> EngineResults:
results = [] res = EngineResults()
res_json = resp.json() res_json = resp.json()
for result in res_json['results']: for result in res_json['results']:
if ddg_category == 'images': if ddg_category == 'images':
results.append(_image_result(result)) res.add(_image_result(result))
elif ddg_category == 'videos': elif ddg_category == 'videos':
results.append(_video_result(result)) res.add(_video_result(result))
elif ddg_category == 'news': elif ddg_category == 'news':
results.append(_news_result(result)) res.add(_news_result(result))
else: else:
raise ValueError(f"Invalid duckduckgo category: {ddg_category}") raise ValueError(f"Invalid duckduckgo category: {ddg_category}")
return results return res

View File

@@ -10,7 +10,6 @@ from searx.utils import (
eval_xpath_getindex, eval_xpath_getindex,
eval_xpath_list, eval_xpath_list,
extract_text, extract_text,
get_embeded_stream_url,
parse_duration_string, parse_duration_string,
) )
@@ -79,7 +78,6 @@ def response(resp: "SXNG_Response") -> EngineResults:
title=title, title=title,
thumbnail=thumbnail, thumbnail=thumbnail,
length=length, length=length,
iframe_src=get_embeded_stream_url(url) or "",
template="videos.html", template="videos.html",
) )
) )

View File

@@ -18,7 +18,6 @@ from searx.utils import (
html_to_text, html_to_text,
parse_duration_string, parse_duration_string,
js_obj_str_to_python, js_obj_str_to_python,
get_embeded_stream_url,
) )
# engine metadata # engine metadata
@@ -195,7 +194,7 @@ def parse_news(data):
def parse_videos(data): def parse_videos(data):
results = [] res = EngineResults()
dom = html.fromstring(data) dom = html.fromstring(data)
@@ -214,15 +213,14 @@ def parse_videos(data):
except (ValueError, TypeError): except (ValueError, TypeError):
pass pass
results.append( res.add(
{ res.types.LegacyResult(
"template": "videos.html", template="videos.html",
"title": extract_text(eval_xpath(item, ".//a[contains(@class, 'info_title')]")), title=extract_text(eval_xpath(item, ".//a[contains(@class, 'info_title')]")),
"url": url, url=url,
"thumbnail": thumbnail, thumbnail=thumbnail,
"length": length, length=length,
"iframe_src": get_embeded_stream_url(url), )
}
) )
return results return res

View File

@@ -14,7 +14,7 @@ from lxml import html
import babel import babel
from searx.enginelib.traits import EngineTraits 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.locales import region_tag
from searx.result_types import EngineResults 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 "", title=extract_text(eval_xpath(result, ".//h2[contains(@class, 'video-card-title')]")) or "",
content=extract_text(eval_xpath(result, ".//p")) or "", content=extract_text(eval_xpath(result, ".//p")) or "",
thumbnail=thumbnail or "", thumbnail=thumbnail or "",
iframe_src=get_embeded_stream_url(url) or "",
) )
) )

View File

@@ -60,9 +60,6 @@ from searx.exceptions import (
SearxEngineTooManyRequestsException, SearxEngineTooManyRequestsException,
) )
from searx.network import raise_for_httperror from searx.network import raise_for_httperror
from searx.utils import (
get_embeded_stream_url,
)
from searx.result_types import EngineResults from searx.result_types import EngineResults
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
@@ -299,7 +296,6 @@ def response(resp: "SXNG_Response") -> EngineResults:
title=title, title=title,
url=res_url, url=res_url,
content=content, content=content,
iframe_src=get_embeded_stream_url(res_url),
publishedDate=pub_date, publishedDate=pub_date,
thumbnail=thumbnail, thumbnail=thumbnail,
template="videos.html", template="videos.html",

View File

@@ -14,7 +14,7 @@ from urllib.parse import urlencode
from lxml import html 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.result_types import EngineResults
from searx.enginelib import EngineAbout from searx.enginelib import EngineAbout
@@ -126,7 +126,6 @@ def _video_results(doc: ElementType, res: EngineResults):
url=url, url=url,
title=" - ".join(extract_text(part) or "" for part in title_parts), title=" - ".join(extract_text(part) or "" for part in title_parts),
thumbnail=extract_text(eval_xpath(result, ".//img/@src") or "") or "", thumbnail=extract_text(eval_xpath(result, ".//img/@src") or "") or "",
iframe_src=get_embeded_stream_url(url) or "",
) )
) )