From d44677e226b2530eea1c0f03806dd920055129cb Mon Sep 17 00:00:00 2001 From: Dalf Date: Wed, 31 Jul 2019 08:37:51 +0200 Subject: [PATCH 1/3] [fix] dailymotion engine: remove HTML tags from the description --- searx/engines/dailymotion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searx/engines/dailymotion.py b/searx/engines/dailymotion.py index 069aceaa3..1038e64bf 100644 --- a/searx/engines/dailymotion.py +++ b/searx/engines/dailymotion.py @@ -15,7 +15,7 @@ from json import loads from datetime import datetime from searx.url_utils import urlencode -from searx.utils import match_language +from searx.utils import match_language, html_to_text # engine dependent config categories = ['videos'] @@ -59,7 +59,7 @@ def response(resp): for res in search_res['list']: title = res['title'] url = res['url'] - content = res['description'] + content = html_to_text(res['description']) thumbnail = res['thumbnail_360_url'] publishedDate = datetime.fromtimestamp(res['created_time'], None) embedded = embedded_url.format(videoid=res['id']) From 8b7ac56669ab355eb1bca92a44372ab9f343f6aa Mon Sep 17 00:00:00 2001 From: Dalf Date: Wed, 31 Jul 2019 08:38:45 +0200 Subject: [PATCH 2/3] [fix] google_videos engine: some results don't a thumbnail --- searx/engines/google_videos.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/searx/engines/google_videos.py b/searx/engines/google_videos.py index 9a41b2dfa..fd6b2e3be 100644 --- a/searx/engines/google_videos.py +++ b/searx/engines/google_videos.py @@ -75,15 +75,17 @@ def response(resp): # get thumbnails script = str(dom.xpath('//script[contains(., "_setImagesSrc")]')[0].text) - id = result.xpath('.//div[@class="s"]//img/@id')[0] - thumbnails_data = re.findall('s=\'(.*?)(?:\\\\[a-z,1-9,\\\\]+\'|\')\;var ii=\[(?:|[\'vidthumb\d+\',]+)\'' + id, - script) - tmp = [] - if len(thumbnails_data) != 0: - tmp = re.findall('(data:image/jpeg;base64,[a-z,A-Z,0-9,/,\+]+)', thumbnails_data[0]) - thumbnail = '' - if len(tmp) != 0: - thumbnail = tmp[-1] + ids = result.xpath('.//div[@class="s"]//img/@id') + if len(ids) > 0: + thumbnails_data = \ + re.findall('s=\'(.*?)(?:\\\\[a-z,1-9,\\\\]+\'|\')\;var ii=\[(?:|[\'vidthumb\d+\',]+)\'' + ids[0], + script) + tmp = [] + if len(thumbnails_data) != 0: + tmp = re.findall('(data:image/jpeg;base64,[a-z,A-Z,0-9,/,\+]+)', thumbnails_data[0]) + thumbnail = '' + if len(tmp) != 0: + thumbnail = tmp[-1] # append result results.append({'url': url, From 0c032c84291954da206e8084553d91add240afd2 Mon Sep 17 00:00:00 2001 From: Dalf Date: Wed, 31 Jul 2019 08:39:40 +0200 Subject: [PATCH 3/3] [fix] youtube_noapi engine: fix the title --- searx/engines/youtube_noapi.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/searx/engines/youtube_noapi.py b/searx/engines/youtube_noapi.py index 53a10bf35..49d0ae604 100644 --- a/searx/engines/youtube_noapi.py +++ b/searx/engines/youtube_noapi.py @@ -67,12 +67,8 @@ def response(resp): if videoid is not None: url = base_youtube_url + videoid thumbnail = 'https://i.ytimg.com/vi/' + videoid + '/hqdefault.jpg' - title = video.get('title', {}).get('simpleText', videoid) - description_snippet = video.get('descriptionSnippet', {}) - if 'runs' in description_snippet: - content = reduce(lambda a, b: a + b.get('text', ''), description_snippet.get('runs'), '') - else: - content = description_snippet.get('simpleText', '') + title = get_text_from_json(video.get('title', {})) + content = get_text_from_json(video.get('descriptionSnippet', {})) embedded = embedded_url.format(videoid=videoid) # append result @@ -85,3 +81,10 @@ def response(resp): # return results return results + + +def get_text_from_json(element): + if 'runs' in element: + return reduce(lambda a, b: a + b.get('text', ''), element.get('runs'), '') + else: + return element.get('simpleText', '')