on master help sign in
[mod] improve video results of the qwant engine

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>

commit2b69710aef92923f7c9126c0d3da73c978a326e3 authorMarkus Heiser <markus.heiser@darmarit.de> dateThu 15 Jul 2021, 20:10 (5 years ago) parent3205785
1 file changed+21−2
searx/engines/qwant.py+21−2
searx/engines/qwant.py+21−2
@@ -29,6 +29,7 @@ from datetime import (
2929)
3030from json import loads
3131from urllib.parse import urlencode
32+from flask_babel import gettext
3233
3334# from searx import logger
3435from searx.utils import match_language
@@ -100,6 +101,7 @@ def request(query, params):
100101
101102def response(resp):
102103 """Get response from Qwant's search request"""
104+ # pylint: disable=too-many-locals, too-many-branches, too-many-statements
103105
104106 keyword = category_to_keyword[categories[0]]
105107 results = []
@@ -180,11 +182,28 @@ def response(resp):
180182 })
181183
182184 elif mainline_type == 'videos':
183− content = item['desc']
185+ # some videos do not have a description: while quant-video
186+ # returns an empty string, such video from a quant-web query
187+ # miss the 'desc' key.
188+ content = item.get('desc', '')
189+ s, c = item.get('source',''), item.get('channel','')
190+ if content and (s or c):
191+ content += " // "
192+ if s:
193+ content += "%s: %s " % (gettext("Source"), s)
194+ if c:
195+ content += "//"
196+ if c:
197+ content += " %s: %s " % (gettext("Channel"), c)
184198 length = timedelta(seconds=item['duration'])
185199 pub_date = datetime.fromtimestamp(item['date'])
186200 thumbnail = item['thumbnail']
187−
201+ # from some locations (DE and others?) the s2 link do
202+ # response a 'Please wait ..' but does not deliver the thumbnail
203+ thumbnail = thumbnail.replace(
204+ 'https://s2.qwant.com',
205+ 'https://s1.qwant.com', 1
206+ )
188207 results.append({
189208 'title': title,
190209 'url': res_url,