2"""Implementations of the favicon *resolvers* that are available in the favicon
3proxy by default. A *resolver* is a function that obtains the favicon from an
4external source. The *resolver* function receives two arguments (``domain,
5timeout``) and returns a tuple ``(data, mime)``.
9from __future__
import annotations
11__all__ = [
"DEFAULT_RESOLVER_MAP",
"allesedv",
"duckduckgo",
"google",
"yandex"]
13from typing
import Callable
14from searx
import network
15from searx
import logger
17DEFAULT_RESOLVER_MAP: dict[str, Callable]
18logger = logger.getChild(
'favicons.resolvers')
23 d = {
"raise_for_httperror":
False}
28def allesedv(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
29 """Favicon Resolver from allesedv.com / https://favicon.allesedv.com/"""
30 data, mime = (
None,
None)
31 url = f
"https://f1.allesedv.com/32/{domain}"
32 logger.debug(
"fetch favicon from: %s", url)
36 response = network.get(url, **
_req_args(timeout=timeout))
37 if response
and response.status_code == 200:
38 mime = response.headers[
'Content-Type']
39 if mime !=
'image/gif':
40 data = response.content
44def duckduckgo(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
45 """Favicon Resolver from duckduckgo.com / https://blog.jim-nielsen.com/2021/displaying-favicons-for-any-domain/"""
46 data, mime = (
None,
None)
47 url = f
"https://icons.duckduckgo.com/ip2/{domain}.ico"
48 logger.debug(
"fetch favicon from: %s", url)
51 response = network.get(url, **
_req_args(timeout=timeout))
52 if response
and response.status_code == 200:
54 mime = response.headers[
'Content-Type']
55 data = response.content
59def google(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
60 """Favicon Resolver from google.com"""
61 data, mime = (
None,
None)
66 f
"https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL"
67 f
"&url=https://{domain}&size=32"
69 logger.debug(
"fetch favicon from: %s", url)
72 response = network.get(url, **
_req_args(timeout=timeout))
73 if response
and response.status_code == 200:
75 mime = response.headers[
'Content-Type']
76 data = response.content
80def yandex(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
81 """Favicon Resolver from yandex.com"""
82 data, mime = (
None,
None)
83 url = f
"https://favicon.yandex.net/favicon/{domain}"
84 logger.debug(
"fetch favicon from: %s", url)
88 response = network.get(url, **
_req_args(timeout=timeout))
89 if response
and response.status_code == 200
and len(response.content) > 70:
90 mime = response.headers[
'Content-Type']
91 data = response.content
95DEFAULT_RESOLVER_MAP = {
97 "duckduckgo": duckduckgo,
tuple[None|bytes, None|str] google(str domain, int timeout)
tuple[None|bytes, None|str] yandex(str domain, int timeout)
tuple[None|bytes, None|str] allesedv(str domain, int timeout)
tuple[None|bytes, None|str] duckduckgo(str domain, int timeout)