.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
tracker_url_remover.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2# pylint: disable=missing-module-docstring, unused-argument
3
4from __future__ import annotations
5
6import logging
7import typing
8
9from flask_babel import gettext
10
11from searx.data import TRACKER_PATTERNS
12
13from . import Plugin, PluginInfo
14
15if typing.TYPE_CHECKING:
16 from searx.search import SearchWithPlugins
17 from searx.extended_types import SXNG_Request
18 from searx.result_types import Result, LegacyResult
19 from searx.plugins import PluginCfg
20
21
22log = logging.getLogger("searx.plugins.tracker_url_remover")
23
24
26 """Remove trackers arguments from the returned URL."""
27
28 id = "tracker_url_remover"
29
30 def __init__(self, plg_cfg: "PluginCfg") -> None:
31
32 super().__init__(plg_cfg)
34 id=self.id,
35 name=gettext("Tracker URL remover"),
36 description=gettext("Remove trackers arguments from the returned URL"),
37 preference_section="privacy",
38 )
39
40 def on_result(self, request: "SXNG_Request", search: "SearchWithPlugins", result: Result) -> bool:
41
42 result.filter_urls(self.filter_url_field)
43 return True
44
45 @classmethod
46 def filter_url_field(cls, result: "Result|LegacyResult", field_name: str, url_src: str) -> bool | str:
47 """Returns bool ``True`` to use URL unchanged (``False`` to ignore URL).
48 If URL should be modified, the returned string is the new URL to use."""
49
50 if not url_src:
51 log.debug("missing a URL in field %s", field_name)
52 return True
53
54 return TRACKER_PATTERNS.clean_url(url=url_src)
bool on_result(self, "SXNG_Request" request, "SearchWithPlugins" search, Result result)