.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.duckduckgo_extra Namespace Reference

Functions

 request (query, params)
 
 _image_result (result)
 
 _video_result (result)
 
 _news_result (result)
 
 response (resp)
 

Variables

logging logger .Logger
 
dict about
 
list categories = ['images', 'web']
 
str ddg_category = 'images'
 
bool paging = True
 
bool safesearch = True
 
bool send_accept_language_header = True
 
dict safesearch_cookies = {0: '-2', 1: None, 2: '1'}
 
dict safesearch_args = {0: '1', 1: None, 2: '1'}
 
dict search_path_map = {'images': 'i', 'videos': 'v', 'news': 'news'}
 

Detailed Description

DuckDuckGo Extra (images, videos, news)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Function Documentation

◆ _image_result()

searx.engines.duckduckgo_extra._image_result ( result)
protected

Definition at line 98 of file duckduckgo_extra.py.

98def _image_result(result):
99 return {
100 'template': 'images.html',
101 'url': result['url'],
102 'title': result['title'],
103 'content': '',
104 'thumbnail_src': result['thumbnail'],
105 'img_src': result['image'],
106 'resolution': '%s x %s' % (result['width'], result['height']),
107 'source': result['source'],
108 }
109
110

Referenced by searx.engines.duckduckgo_extra.response().

+ Here is the caller graph for this function:

◆ _news_result()

searx.engines.duckduckgo_extra._news_result ( result)
protected

Definition at line 125 of file duckduckgo_extra.py.

125def _news_result(result):
126 return {
127 'url': result['url'],
128 'title': result['title'],
129 'content': result['excerpt'],
130 'source': result['source'],
131 'publishedDate': datetime.utcfromtimestamp(result['date']),
132 }
133
134

Referenced by searx.engines.duckduckgo_extra.response().

+ Here is the caller graph for this function:

◆ _video_result()

searx.engines.duckduckgo_extra._video_result ( result)
protected

Definition at line 111 of file duckduckgo_extra.py.

111def _video_result(result):
112 return {
113 'template': 'videos.html',
114 'url': result['content'],
115 'title': result['title'],
116 'content': result['description'],
117 'thumbnail': result['images'].get('small') or result['images'].get('medium'),
118 'iframe_src': get_embeded_stream_url(result['content']),
119 'source': result['provider'],
120 'length': result['duration'],
121 'metadata': result.get('uploader'),
122 }
123
124

Referenced by searx.engines.duckduckgo_extra.response().

+ Here is the caller graph for this function:

◆ request()

searx.engines.duckduckgo_extra.request ( query,
params )

Definition at line 49 of file duckduckgo_extra.py.

49def request(query, params):
50 eng_region: str = traits.get_region(params['searxng_locale'], traits.all_locale) # type: ignore
51
52 # request needs a vqd argument
53 vqd = get_vqd(query, eng_region, force_request=True)
54
55 if not vqd:
56 # some search terms do not have results and therefore no vqd value
57 params['url'] = None
58 return params
59
60 eng_lang = get_ddg_lang(traits, params['searxng_locale'])
61
62 args = {
63 'q': query,
64 'o': 'json',
65 # 'u': 'bing',
66 'l': eng_region,
67 'f': ',,,,,',
68 'vqd': vqd,
69 }
70
71 if params['pageno'] > 1:
72 args['s'] = (params['pageno'] - 1) * 100
73
74 params['cookies']['ad'] = eng_lang # zh_CN
75 params['cookies']['ah'] = eng_region # "us-en,de-de"
76 params['cookies']['l'] = eng_region # "hk-tzh"
77
78 safe_search = safesearch_cookies.get(params['safesearch'])
79 if safe_search is not None:
80 params['cookies']['p'] = safe_search # "-2", "1"
81 safe_search = safesearch_args.get(params['safesearch'])
82 if safe_search is not None:
83 args['p'] = safe_search # "-1", "1"
84
85 logger.debug("cookies: %s", params['cookies'])
86
87 params['url'] = f'https://duckduckgo.com/{search_path_map[ddg_category]}.js?{urlencode(args)}'
88
89 # sending these two headers prevents rate limiting for the query
90 params['headers'] = {
91 'Referer': 'https://duckduckgo.com/',
92 'X-Requested-With': 'XMLHttpRequest',
93 }
94
95 return params
96
97

◆ response()

searx.engines.duckduckgo_extra.response ( resp)

Definition at line 135 of file duckduckgo_extra.py.

135def response(resp):
136 results = []
137 res_json = resp.json()
138
139 for result in res_json['results']:
140 if ddg_category == 'images':
141 results.append(_image_result(result))
142 elif ddg_category == 'videos':
143 results.append(_video_result(result))
144 elif ddg_category == 'news':
145 results.append(_news_result(result))
146 else:
147 raise ValueError(f"Invalid duckduckgo category: {ddg_category}")
148
149 return results

References searx.engines.duckduckgo_extra._image_result(), searx.engines.duckduckgo_extra._news_result(), and searx.engines.duckduckgo_extra._video_result().

+ Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.duckduckgo_extra.about
Initial value:
1= {
2 "website": 'https://duckduckgo.com/',
3 "wikidata_id": 'Q12805',
4 "use_official_api": False,
5 "require_api_key": False,
6 "results": 'JSON (site requires js to get images)',
7}

Definition at line 26 of file duckduckgo_extra.py.

◆ categories

list searx.engines.duckduckgo_extra.categories = ['images', 'web']

Definition at line 35 of file duckduckgo_extra.py.

◆ ddg_category

str searx.engines.duckduckgo_extra.ddg_category = 'images'

Definition at line 36 of file duckduckgo_extra.py.

◆ logger

logging searx.engines.duckduckgo_extra.logger .Logger

Definition at line 21 of file duckduckgo_extra.py.

◆ paging

bool searx.engines.duckduckgo_extra.paging = True

Definition at line 39 of file duckduckgo_extra.py.

◆ safesearch

bool searx.engines.duckduckgo_extra.safesearch = True

Definition at line 40 of file duckduckgo_extra.py.

◆ safesearch_args

dict searx.engines.duckduckgo_extra.safesearch_args = {0: '1', 1: None, 2: '1'}

Definition at line 44 of file duckduckgo_extra.py.

◆ safesearch_cookies

dict searx.engines.duckduckgo_extra.safesearch_cookies = {0: '-2', 1: None, 2: '1'}

Definition at line 43 of file duckduckgo_extra.py.

◆ search_path_map

dict searx.engines.duckduckgo_extra.search_path_map = {'images': 'i', 'videos': 'v', 'news': 'news'}

Definition at line 46 of file duckduckgo_extra.py.

◆ send_accept_language_header

bool searx.engines.duckduckgo_extra.send_accept_language_header = True

Definition at line 41 of file duckduckgo_extra.py.