on master help sign in
fix vimeo engine and add comments

engine generate (Error: None), I don't know why

commit58a443be29e9fda5273af5118d72ff512ecb9e08 authorThomas Pointhuber <thomas.pointhuber@gmx.at> dateMon 1 Sep 2014, 17:10 (12 years ago) parent03db970
2 files changed+41−27
searx/engines/vimeo.py+40−22 searx/settings.yml+1−5
searx/engines/vimeo.py+40−22
@@ -1,43 +1,58 @@
1+## Vimeo (Videos)
2+#
3+# @website https://vimeo.com/
4+# @provide-api yes (http://developer.vimeo.com/api), they have a maximum count of queries/hour
5+#
6+# @using-api no (TODO, rewrite to api)
7+# @results HTML (using search portal)
8+# @stable no (HTML can change)
9+# @parse url, title, publishedDate, thumbnail
10+#
11+# @todo rewrite to api
12+# @todo set content-parameter with correct data
13+
114from urllib import urlencode
215from HTMLParser import HTMLParser
316from lxml import html
417from searx.engines.xpath import extract_text
518from dateutil import parser
619
7−base_url = 'http://vimeo.com'
8−search_url = base_url + '/search?{query}'
9−url_xpath = None
10−content_xpath = None
11−title_xpath = None
12−results_xpath = ''
13−content_tpl = '<a href="{0}"> <img src="{2}"/> </a>'
14−publishedDate_xpath = './/p[@class="meta"]//attribute::datetime'
20+# engine dependent config
21+categories = ['videos']
22+paging = True
1523
16−# the cookie set by vimeo contains all the following values,
17−# but only __utma seems to be requiered
18−cookie = {
19− #'vuid':'918282893.1027205400'
20− # 'ab_bs':'%7B%223%22%3A279%7D'
21− '__utma': '00000000.000#0000000.0000000000.0000000000.0000000000.0'
22− # '__utmb':'18302654.1.10.1388942090'
23− #, '__utmc':'18302654'
24− #, '__utmz':'18#302654.1388942090.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)' # noqa
25− #, '__utml':'search'
26−}
24+# search-url
25+base_url = 'https://vimeo.com'
26+search_url = base_url + '/search/page:{pageno}?{query}'
27+
28+# specific xpath variables
29+url_xpath = './a/@href'
30+content_xpath = './a/img/@src'
31+title_xpath = './a/div[@class="data"]/p[@class="title"]/text()'
32+results_xpath = '//div[@id="browse_content"]/ol/li'
33+publishedDate_xpath = './/p[@class="meta"]//attribute::datetime'
2734
2835
36+# do search-request
2937def request(query, params):
30− params['url'] = search_url.format(query=urlencode({'q': query}))
31− params['cookies'] = cookie
38+ params['url'] = search_url.format(pageno=params['pageno'] ,
39+ query=urlencode({'q': query}))
40+
41+ # TODO required?
42+ params['cookies']['__utma'] = '00000000.000#0000000.0000000000.0000000000.0000000000.0'
43+
3244 return params
3345
3446
47+# get response from search-request
3548def response(resp):
3649 results = []
50+
3751 dom = html.fromstring(resp.text)
3852
3953 p = HTMLParser()
4054
55+ # parse results
4156 for result in dom.xpath(results_xpath):
4257 url = base_url + result.xpath(url_xpath)[0]
4358 title = p.unescape(extract_text(result.xpath(title_xpath)))
@@ -45,10 +60,13 @@ def response(resp):
4560 publishedDate = parser.parse(extract_text(
4661 result.xpath(publishedDate_xpath)[0]))
4762
63+ # append result
4864 results.append({'url': url,
4965 'title': title,
50− 'content': content_tpl.format(url, title, thumbnail),
66+ 'content': '',
5167 'template': 'videos.html',
5268 'publishedDate': publishedDate,
5369 'thumbnail': thumbnail})
70+
71+ # return results
5472 return results
searx/settings.yml+1−5
@@ -153,11 +153,7 @@ engines:
153153
154154 - name : vimeo
155155 engine : vimeo
156− categories : videos
157− results_xpath : //div[@id="browse_content"]/ol/li
158− url_xpath : ./a/@href
159− title_xpath : ./a/div[@class="data"]/p[@class="title"]/text()
160− content_xpath : ./a/img/@src
156+ locale : en-US
161157 shortcut : vm
162158
163159locales: