@@ -1,45 +1,61 @@
1+## Dailymotion (Videos)
2+#
3+# @website https://www.dailymotion.com
4+# @provide-api yes (http://www.dailymotion.com/developer)
5+#
6+# @using-api yes
7+# @results JSON
8+# @stable yes
9+# @parse url, title, thumbnail
10+#
11+# @todo set content-parameter with correct data
12+
113from urllib import urlencode
214from json import loads
315from lxml import html
416
17+# engine dependent config
518categories = ['videos']
619locale = 'en_US'
20+paging = True
721
22+# search-url
823# see http://www.dailymotion.com/doc/api/obj-video.html
9−search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=25&page={pageno}&{query}' # noqa
10−
11−# TODO use video result template
12−content_tpl = '<a href="{0}" title="{0}" ><img src="{1}" /></a><br />'
13−
14−paging = True
24+search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=5&page={pageno}&{query}' # noqa
1525
1626
27+# do search-request
1728def request(query, params):
1829 params['url'] = search_url.format(
1930 query=urlencode({'search': query, 'localization': locale}),
2031 pageno=params['pageno'])
32+
2133 return params
2234
2335
36+# get response from search-request
2437def response(resp):
2538 results = []
39+
2640 search_res = loads(resp.text)
41+
42+ # return empty array if there are no results
2743 if not 'list' in search_res:
28− return results
44+ return []
45+
46+ # parse results
2947 for res in search_res['list']:
3048 title = res['title']
3149 url = res['url']
32− if res['thumbnail_360_url']:
33− content = content_tpl.format(url, res['thumbnail_360_url'])
34− else:
35− content = ''
36− if res['description']:
37− description = text_content_from_html(res['description'])
38− content += description[:500]
39− results.append({'url': url, 'title': title, 'content': content})
40− return results
50+ #content = res['description']
51+ content = ''
52+ thumbnail = res['thumbnail_360_url']
4153
54+ results.append({'template': 'videos.html',
55+ 'url': url,
56+ 'title': title,
57+ 'content': content,
58+ 'thumbnail': thumbnail})
4259
43−def text_content_from_html(html_string):
44− desc_html = html.fragment_fromstring(html_string, create_parent=True)
45− return desc_html.text_content()
60+ # return results
61+ return results