.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 92 of file duckduckgo_extra.py.

92def _image_result(result):
93 return {
94 'template': 'images.html',
95 'url': result['url'],
96 'title': result['title'],
97 'content': '',
98 'thumbnail_src': result['thumbnail'],
99 'img_src': result['image'],
100 'resolution': '%s x %s' % (result['width'], result['height']),
101 'source': result['source'],
102 }
103
104

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 119 of file duckduckgo_extra.py.

119def _news_result(result):
120 return {
121 'url': result['url'],
122 'title': result['title'],
123 'content': result['excerpt'],
124 'source': result['source'],
125 'publishedDate': datetime.utcfromtimestamp(result['date']),
126 }
127
128

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 105 of file duckduckgo_extra.py.

105def _video_result(result):
106 return {
107 'template': 'videos.html',
108 'url': result['content'],
109 'title': result['title'],
110 'content': result['description'],
111 'thumbnail': result['images'].get('small') or result['images'].get('medium'),
112 'iframe_src': get_embeded_stream_url(result['content']),
113 'source': result['provider'],
114 'length': result['duration'],
115 'metadata': result.get('uploader'),
116 }
117
118

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 50 of file duckduckgo_extra.py.

50def request(query, params):
51
52 # request needs a vqd argument
53 vqd = get_vqd(query)
54 if not vqd:
55 # some search terms do not have results and therefore no vqd value
56 params['url'] = None
57 return params
58
59 eng_region = traits.get_region(params['searxng_locale'], traits.all_locale)
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 return params
90
91

◆ response()

searx.engines.duckduckgo_extra.response ( resp)

Definition at line 129 of file duckduckgo_extra.py.

129def response(resp):
130 results = []
131 res_json = resp.json()
132
133 for result in res_json['results']:
134 if ddg_category == 'images':
135 results.append(_image_result(result))
136 elif ddg_category == 'videos':
137 results.append(_video_result(result))
138 elif ddg_category == 'news':
139 results.append(_news_result(result))
140 else:
141 raise ValueError(f"Invalid duckduckgo category: {ddg_category}")
142
143 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 27 of file duckduckgo_extra.py.

◆ categories

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

Definition at line 36 of file duckduckgo_extra.py.

◆ ddg_category

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

Definition at line 37 of file duckduckgo_extra.py.

◆ logger

logging searx.engines.duckduckgo_extra.logger .Logger

Definition at line 22 of file duckduckgo_extra.py.

◆ paging

bool searx.engines.duckduckgo_extra.paging = True

Definition at line 40 of file duckduckgo_extra.py.

◆ safesearch

bool searx.engines.duckduckgo_extra.safesearch = True

Definition at line 41 of file duckduckgo_extra.py.

◆ safesearch_args

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

Definition at line 45 of file duckduckgo_extra.py.

◆ safesearch_cookies

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

Definition at line 44 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 47 of file duckduckgo_extra.py.

◆ send_accept_language_header

bool searx.engines.duckduckgo_extra.send_accept_language_header = True

Definition at line 42 of file duckduckgo_extra.py.