|
@@ -1,16 +1,17 @@
|
1
|
1
|
from urllib import urlencode
|
|
2
|
+from lxml import html
|
2
|
3
|
from json import loads
|
3
|
4
|
from cgi import escape
|
4
|
5
|
|
5
|
6
|
categories = ['videos']
|
6
|
|
-localization = 'en'
|
|
7
|
+locale = 'en_US'
|
7
|
8
|
|
8
|
9
|
# see http://www.dailymotion.com/doc/api/obj-video.html
|
9
|
10
|
search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=25&page=1&{query}'
|
10
|
11
|
|
11
|
12
|
def request(query, params):
|
12
|
13
|
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 }))
|
14
|
15
|
return params
|
15
|
16
|
|
16
|
17
|
|
|
@@ -27,6 +28,11 @@ def response(resp):
|
27
|
28
|
else:
|
28
|
29
|
content = ''
|
29
|
30
|
if res['description']:
|
30
|
|
- content += escape(res['description'][:500])
|
|
31
|
+ description = text_content_from_html(res['description'])
|
|
32
|
+ content += description[:500]
|
31
|
33
|
results.append({'url': url, 'title': title, 'content': content})
|
32
|
34
|
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()
|