on master help sign in
[fix] dailymotion engine : no more html tag in the description
commit49c85fce51c2b8431013d9269999eac5a6a9c038 authorDalf <alex@al-f.net> dateSun 5 Jan 2014, 13:55 (13 years ago) parente88cf0a
2 files changed+10−3
engines.cfg_sample+1 searx/engines/dailymotion.py+9−3
engines.cfg_sample+1
@@ -82,5 +82,6 @@ categories = videos
8282
8383[dailymotion]
8484engine = dailymotion
85+locale = en_US
8586categories = videos
8687
searx/engines/dailymotion.py+9−3
@@ -1,16 +1,17 @@
11from urllib import urlencode
2+from lxml import html
23from json import loads
34from cgi import escape
45
56categories = ['videos']
6−localization = 'en'
7+locale = 'en_US'
78
89# see http://www.dailymotion.com/doc/api/obj-video.html
910search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=25&page=1&{query}'
1011
1112def request(query, params):
1213 global search_url
13− params['url'] = search_url.format(query=urlencode({'search': query, 'localization': localization }))
14+ params['url'] = search_url.format(query=urlencode({'search': query, 'localization': locale }))
1415 return params
1516
1617
@@ -27,6 +28,11 @@ def response(resp):
2728 else:
2829 content = ''
2930 if res['description']:
30− content += escape(res['description'][:500])
31+ description = text_content_from_html(res['description'])
32+ content += description[:500]
3133 results.append({'url': url, 'title': title, 'content': content})
3234 return results
35+
36+def text_content_from_html(html_string):
37+ desc_html = html.fragment_fromstring(html_string, create_parent=True)
38+ return desc_html.text_content()