From 49c85fce51c2b8431013d9269999eac5a6a9c038 Mon Sep 17 00:00:00 2001 From: Dalf Date: Sun, 5 Jan 2014 13:55:17 +0100 Subject: [PATCH] [fix] dailymotion engine : no more html tag in the description --- engines.cfg_sample | 1 + searx/engines/dailymotion.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/engines.cfg_sample b/engines.cfg_sample index d76d31214..e2668eeb1 100644 --- a/engines.cfg_sample +++ b/engines.cfg_sample @@ -82,5 +82,6 @@ categories = videos [dailymotion] engine = dailymotion +locale = en_US categories = videos diff --git a/searx/engines/dailymotion.py b/searx/engines/dailymotion.py index 7046132f3..655485957 100644 --- a/searx/engines/dailymotion.py +++ b/searx/engines/dailymotion.py @@ -1,16 +1,17 @@ from urllib import urlencode +from lxml import html from json import loads from cgi import escape categories = ['videos'] -localization = 'en' +locale = 'en_US' # see http://www.dailymotion.com/doc/api/obj-video.html search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=25&page=1&{query}' def request(query, params): global search_url - params['url'] = search_url.format(query=urlencode({'search': query, 'localization': localization })) + params['url'] = search_url.format(query=urlencode({'search': query, 'localization': locale })) return params @@ -27,6 +28,11 @@ def response(resp): else: content = '' if res['description']: - content += escape(res['description'][:500]) + description = text_content_from_html(res['description']) + content += description[:500] results.append({'url': url, 'title': title, 'content': content}) return results + +def text_content_from_html(html_string): + desc_html = html.fragment_fromstring(html_string, create_parent=True) + return desc_html.text_content()