.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.favicons.resolvers Namespace Reference

Functions

 _req_args (**kwargs)
 
tuple[None|bytes, None|str] allesedv (str domain, int timeout)
 
tuple[None|bytes, None|str] duckduckgo (str domain, int timeout)
 
tuple[None|bytes, None|str] google (str domain, int timeout)
 
tuple[None|bytes, None|str] yandex (str domain, int timeout)
 

Variables

list __all__ = ["DEFAULT_RESOLVER_MAP", "allesedv", "duckduckgo", "google", "yandex"]
 
dict DEFAULT_RESOLVER_MAP [str, Callable]
 
 logger = logger.getChild('favicons.resolvers')
 

Detailed Description

Implementations of the favicon *resolvers* that are available in the favicon
proxy by default.  A *resolver* is a function that obtains the favicon from an
external source.  The *resolver* function receives two arguments (``domain,
timeout``) and returns a tuple ``(data, mime)``.

Function Documentation

◆ _req_args()

searx.favicons.resolvers._req_args ( ** kwargs)
protected

Definition at line 21 of file resolvers.py.

21def _req_args(**kwargs):
22 # add the request arguments from the searx.network
23 d = {"raise_for_httperror": False}
24 d.update(kwargs)
25 return d
26
27

Referenced by searx.favicons.resolvers.allesedv(), searx.favicons.resolvers.duckduckgo(), searx.favicons.resolvers.google(), and searx.favicons.resolvers.yandex().

+ Here is the caller graph for this function:

◆ allesedv()

tuple[None | bytes, None | str] searx.favicons.resolvers.allesedv ( str domain,
int timeout )
Favicon Resolver from allesedv.com / https://favicon.allesedv.com/

Definition at line 28 of file resolvers.py.

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)
33
34 # will just return a 200 regardless of the favicon existing or not
35 # sometimes will be correct size, sometimes not
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
41 return data, mime
42
43

References searx.favicons.resolvers._req_args().

+ Here is the call graph for this function:

◆ duckduckgo()

tuple[None | bytes, None | str] searx.favicons.resolvers.duckduckgo ( str domain,
int timeout )
Favicon Resolver from duckduckgo.com / https://blog.jim-nielsen.com/2021/displaying-favicons-for-any-domain/

Definition at line 44 of file resolvers.py.

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)
49
50 # will return a 404 if the favicon does not exist and a 200 if it does,
51 response = network.get(url, **_req_args(timeout=timeout))
52 if response and response.status_code == 200:
53 # api will respond with a 32x32 png image
54 mime = response.headers['Content-Type']
55 data = response.content
56 return data, mime
57
58

References searx.favicons.resolvers._req_args().

+ Here is the call graph for this function:

◆ google()

tuple[None | bytes, None | str] searx.favicons.resolvers.google ( str domain,
int timeout )
Favicon Resolver from google.com

Definition at line 59 of file resolvers.py.

59def google(domain: str, timeout: int) -> tuple[None | bytes, None | str]:
60 """Favicon Resolver from google.com"""
61 data, mime = (None, None)
62
63 # URL https://www.google.com/s2/favicons?sz=32&domain={domain}" will be
64 # redirected (HTTP 301 Moved Permanently) to t1.gstatic.com/faviconV2:
65 url = (
66 f"https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL"
67 f"&url=https://{domain}&size=32"
68 )
69 logger.debug("fetch favicon from: %s", url)
70
71 # will return a 404 if the favicon does not exist and a 200 if it does,
72 response = network.get(url, **_req_args(timeout=timeout))
73 if response and response.status_code == 200:
74 # api will respond with a 32x32 png image
75 mime = response.headers['Content-Type']
76 data = response.content
77 return data, mime
78
79

References searx.favicons.resolvers._req_args().

+ Here is the call graph for this function:

◆ yandex()

tuple[None | bytes, None | str] searx.favicons.resolvers.yandex ( str domain,
int timeout )
Favicon Resolver from yandex.com

Definition at line 80 of file resolvers.py.

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)
85
86 # api will respond with a 16x16 png image, if it doesn't exist, it will be a
87 # 1x1 png image (70 bytes)
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
92 return data, mime
93
94

References searx.favicons.resolvers._req_args().

+ Here is the call graph for this function:

Variable Documentation

◆ __all__

list searx.favicons.resolvers.__all__ = ["DEFAULT_RESOLVER_MAP", "allesedv", "duckduckgo", "google", "yandex"]
private

Definition at line 11 of file resolvers.py.

◆ DEFAULT_RESOLVER_MAP

dict searx.favicons.resolvers.DEFAULT_RESOLVER_MAP [str, Callable]

Definition at line 17 of file resolvers.py.

◆ logger

searx.favicons.resolvers.logger = logger.getChild('favicons.resolvers')

Definition at line 18 of file resolvers.py.