ahmia_filter.py 872 B

1234567891011121314151617181920212223242526272829
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # pylint: disable=missing-module-docstring
  3. from hashlib import md5
  4. from searx.data import ahmia_blacklist_loader
  5. name = "Ahmia blacklist"
  6. description = "Filter out onion results that appear in Ahmia's blacklist. (See https://ahmia.fi/blacklist)"
  7. default_on = True
  8. preference_section = 'onions'
  9. ahmia_blacklist = None
  10. def on_result(_request, _search, result):
  11. if not result.get('is_onion') or not result.get('parsed_url'):
  12. return True
  13. result_hash = md5(result['parsed_url'].hostname.encode()).hexdigest()
  14. return result_hash not in ahmia_blacklist
  15. def init(_app, settings):
  16. global ahmia_blacklist # pylint: disable=global-statement
  17. if not settings['outgoing']['using_tor_proxy']:
  18. # disable the plugin
  19. return False
  20. ahmia_blacklist = ahmia_blacklist_loader()
  21. return True