@@ -1,45 +1,61 @@
1+## Dailymotion (Videos)
3+# @website https://www.dailymotion.com
4+# @provide-api yes (http://www.dailymotion.com/developer)
9+# @parse url, title, thumbnail
11+# @todo set content-parameter with correct data
1from urllib import urlencode
13from urllib import urlencode
2from json import loads
14from json import loads
3from lxml import html
15from lxml import html
17+# engine dependent config
5categories = ['videos']
18categories = ['videos']
6locale = 'en_US'
19locale = 'en_US'
8# see http://www.dailymotion.com/doc/api/obj-video.html
23# 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
24+search_url = 'https://api.dailymotion.com/videos?fields=title,description,duration,url,thumbnail_360_url&sort=relevance&limit=5&page={pageno}&{query}' # noqa
11−# TODO use video result template
12−content_tpl = '<a href="{0}" title="{0}" ><img src="{1}" /></a><br />'
17def request(query, params):
28def request(query, params):
18 params['url'] = search_url.format(
29 params['url'] = search_url.format(
19 query=urlencode({'search': query, 'localization': locale}),
30 query=urlencode({'search': query, 'localization': locale}),
20 pageno=params['pageno'])
31 pageno=params['pageno'])
21 return params
33 return params
36+# get response from search-request
24def response(resp):
37def response(resp):
25 results = []
38 results = []
26 search_res = loads(resp.text)
40 search_res = loads(resp.text)
42+ # return empty array if there are no results
27 if not 'list' in search_res:
43 if not 'list' in search_res:
28− return results
44+ return []
29 for res in search_res['list']:
47 for res in search_res['list']:
30 title = res['title']
48 title = res['title']
31 url = res['url']
49 url = res['url']
32− if res['thumbnail_360_url']:
50+ #content = res['description']
33− content = content_tpl.format(url, res['thumbnail_360_url'])
35− content = ''
51+ content = ''
36− if res['description']:
52+ thumbnail = res['thumbnail_360_url']
37− description = text_content_from_html(res['description'])
38− content += description[:500]
39− results.append({'url': url, 'title': title, 'content': content})
54+ results.append({'template': 'videos.html',
58+ 'thumbnail': thumbnail})
43−def text_content_from_html(html_string):
60+ # return results
44− desc_html = html.fragment_fromstring(html_string, create_parent=True)
61+ return results
45− return desc_html.text_content()