123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- from urllib import urlencode
- from lxml import html
- from HTMLParser import HTMLParser
- from searx.engines.xpath import extract_text
- from dateutil import parser
- categories = ['videos']
- paging = True
- base_url = 'http://vimeo.com'
- search_url = base_url + '/search/page:{pageno}?{query}'
- results_xpath = '//div[@id="browse_content"]/ol/li'
- url_xpath = './a/@href'
- title_xpath = './a/div[@class="data"]/p[@class="title"]'
- content_xpath = './a/img/@src'
- publishedDate_xpath = './/p[@class="meta"]//attribute::datetime'
- embedded_url = '<iframe data-src="//player.vimeo.com/video{videoid}" ' +\
- 'width="540" height="304" frameborder="0" ' +\
- 'webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'
- def request(query, params):
- params['url'] = search_url.format(pageno=params['pageno'],
- query=urlencode({'q': query}))
- return params
- def response(resp):
- results = []
- dom = html.fromstring(resp.text)
- p = HTMLParser()
-
- for result in dom.xpath(results_xpath):
- videoid = result.xpath(url_xpath)[0]
- url = base_url + videoid
- title = p.unescape(extract_text(result.xpath(title_xpath)))
- thumbnail = extract_text(result.xpath(content_xpath)[0])
- publishedDate = parser.parse(extract_text(result.xpath(publishedDate_xpath)[0]))
- embedded = embedded_url.format(videoid=videoid)
-
- results.append({'url': url,
- 'title': title,
- 'content': '',
- 'template': 'videos.html',
- 'publishedDate': publishedDate,
- 'embedded': embedded,
- 'thumbnail': thumbnail})
-
- return results
|