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)``.
10__all__ = [
"DEFAULT_RESOLVER_MAP",
"allesedv",
"duckduckgo",
"google",
"yandex"]
12from typing
import Callable
13from searx
import network
14from searx
import logger
16DEFAULT_RESOLVER_MAP: dict[str, Callable]
17logger = logger.getChild(
'favicons.resolvers')
22 d = {
"raise_for_httperror":
False}
27def allesedv(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
28 """Favicon Resolver from allesedv.com / https://favicon.allesedv.com/"""
29 data, mime = (
None,
None)
30 url = f
"https://f1.allesedv.com/32/{domain}"
31 logger.debug(
"fetch favicon from: %s", url)
35 response = network.get(url, **
_req_args(timeout=timeout))
36 if response
and response.status_code == 200:
37 mime = response.headers[
'Content-Type']
38 if mime !=
'image/gif':
39 data = response.content
43def duckduckgo(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
44 """Favicon Resolver from duckduckgo.com / https://blog.jim-nielsen.com/2021/displaying-favicons-for-any-domain/"""
45 data, mime = (
None,
None)
46 url = f
"https://icons.duckduckgo.com/ip2/{domain}.ico"
47 logger.debug(
"fetch favicon from: %s", url)
50 response = network.get(url, **
_req_args(timeout=timeout))
51 if response
and response.status_code == 200:
53 mime = response.headers[
'Content-Type']
54 data = response.content
58def google(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
59 """Favicon Resolver from google.com"""
60 data, mime = (
None,
None)
65 f
"https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL"
66 f
"&url=https://{domain}&size=32"
68 logger.debug(
"fetch favicon from: %s", url)
71 response = network.get(url, **
_req_args(timeout=timeout))
72 if response
and response.status_code == 200:
74 mime = response.headers[
'Content-Type']
75 data = response.content
79def yandex(domain: str, timeout: int) -> tuple[
None | bytes,
None | str]:
80 """Favicon Resolver from yandex.com"""
81 data, mime = (
None,
None)
82 url = f
"https://favicon.yandex.net/favicon/{domain}"
83 logger.debug(
"fetch favicon from: %s", url)
87 response = network.get(url, **
_req_args(timeout=timeout))
88 if response
and response.status_code == 200
and len(response.content) > 70:
89 mime = response.headers[
'Content-Type']
90 data = response.content
94DEFAULT_RESOLVER_MAP = {
96 "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)