mirror of
https://github.com/searxng/searxng.git
synced 2025-12-22 19:50:00 +00:00
Compare commits
4 Commits
431bf5d235
...
b299386d3e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b299386d3e | ||
|
|
21a4622f23 | ||
|
|
041f457dfa | ||
|
|
af111e413c |
@@ -89,6 +89,9 @@ time_range_support = True
|
||||
send_accept_language_header = True
|
||||
categories = ["general", "web"] # general, images, videos, news
|
||||
|
||||
# HTTP2 requests immediately get blocked by a CAPTCHA
|
||||
enable_http2 = False
|
||||
|
||||
search_type = "search"
|
||||
"""must be any of ``search``, ``images``, ``videos``, ``news``"""
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ Implementations
|
||||
import typing as t
|
||||
|
||||
from datetime import date, timedelta
|
||||
from urllib.parse import urlencode, quote
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from searx.result_types import EngineResults
|
||||
|
||||
@@ -122,15 +122,14 @@ def response(resp: "SXNG_Response") -> EngineResults:
|
||||
|
||||
url = result.get("url", "").replace("file://" + mount_prefix, dl_prefix)
|
||||
|
||||
mtype = subtype = result.get("mime", "")
|
||||
mtype = subtype = result.get("mtype", "")
|
||||
if mtype:
|
||||
mtype, subtype = (mtype.split("/", 1) + [""])[:2]
|
||||
|
||||
# facilitate preview support for known mime types
|
||||
thumbnail = embedded = ""
|
||||
if mtype in ["audio", "video"]:
|
||||
embedded_url = '<{ttype} controls height="166px" ' + 'src="{url}" type="{mtype}"></{ttype}>'
|
||||
embedded = embedded_url.format(ttype=mtype, url=quote(url.encode("utf8"), "/:"), mtype=result["mtype"])
|
||||
embedded = url
|
||||
if mtype in ["image"] and subtype in ["bmp", "gif", "jpeg", "png"]:
|
||||
thumbnail = url
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import httpx
|
||||
if typing.TYPE_CHECKING:
|
||||
import searx.preferences
|
||||
import searx.results
|
||||
from searx.search.processors import ParamTypes
|
||||
from searx.search.processors import OnlineParamTypes
|
||||
|
||||
|
||||
class SXNG_Request(flask.Request):
|
||||
@@ -83,4 +83,4 @@ class SXNG_Response(httpx.Response):
|
||||
"""
|
||||
|
||||
ok: bool
|
||||
search_params: "ParamTypes"
|
||||
search_params: "OnlineParamTypes"
|
||||
|
||||
@@ -35,7 +35,7 @@ class HTTPParams(t.TypedDict):
|
||||
headers: dict[str, str]
|
||||
"""HTTP header information."""
|
||||
|
||||
data: dict[str, str]
|
||||
data: dict[str, str | int | dict[str, str | int]]
|
||||
"""Sending `form encoded data`_.
|
||||
|
||||
.. _form encoded data:
|
||||
@@ -56,7 +56,7 @@ class HTTPParams(t.TypedDict):
|
||||
https://www.python-httpx.org/quickstart/#sending-json-encoded-data
|
||||
"""
|
||||
|
||||
url: str
|
||||
url: str | None
|
||||
"""Requested url."""
|
||||
|
||||
cookies: dict[str, str]
|
||||
@@ -200,7 +200,7 @@ class OnlineProcessor(EngineProcessor):
|
||||
request_args["content"] = params["content"]
|
||||
|
||||
# send the request
|
||||
response = req(params["url"], **request_args)
|
||||
response = req(params["url"], **request_args) # pyright: ignore[reportArgumentType]
|
||||
|
||||
# check soft limit of the redirect count
|
||||
if len(response.history) > soft_max_redirects:
|
||||
|
||||
@@ -741,7 +741,7 @@ def detect_language(text: str, threshold: float = 0.3, only_search_languages: bo
|
||||
return None
|
||||
|
||||
|
||||
def js_variable_to_python(js_variable: str) -> str:
|
||||
def js_variable_to_python(js_variable: str) -> t.Any:
|
||||
"""Convert a javascript variable into JSON and then load the value
|
||||
|
||||
It does not deal with all cases, but it is good enough for now.
|
||||
@@ -807,13 +807,8 @@ def js_variable_to_python(js_variable: str) -> str:
|
||||
s = _JS_DECIMAL_RE.sub(":0.", s)
|
||||
# replace the surogate character by colon
|
||||
s = s.replace(chr(1), ':')
|
||||
# replace single-quote followed by comma with double-quote and comma
|
||||
# {"a": "\"12\"',"b": "13"}
|
||||
# becomes
|
||||
# {"a": "\"12\"","b": "13"}
|
||||
s = s.replace("',", "\",")
|
||||
# load the JSON and return the result
|
||||
return json.loads(s) # pyright: ignore[reportAny]
|
||||
return json.loads(s)
|
||||
|
||||
|
||||
def parse_duration_string(duration_str: str) -> timedelta | None:
|
||||
|
||||
Reference in New Issue
Block a user