logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

vimeo.py (2112B)


  1. # Vimeo (Videos)
  2. #
  3. # @website https://vimeo.com/
  4. # @provide-api yes (http://developer.vimeo.com/api),
  5. # they have a maximum count of queries/hour
  6. #
  7. # @using-api no (TODO, rewrite to api)
  8. # @results HTML (using search portal)
  9. # @stable no (HTML can change)
  10. # @parse url, title, publishedDate, thumbnail, embedded
  11. #
  12. # @todo rewrite to api
  13. # @todo set content-parameter with correct data
  14. from json import loads
  15. from dateutil import parser
  16. from searx.url_utils import urlencode
  17. # engine dependent config
  18. categories = ['videos']
  19. paging = True
  20. # search-url
  21. base_url = 'https://vimeo.com/'
  22. search_url = base_url + '/search/page:{pageno}?{query}'
  23. embedded_url = '<iframe data-src="//player.vimeo.com/video/{videoid}" ' +\
  24. 'width="540" height="304" frameborder="0" ' +\
  25. 'webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'
  26. # do search-request
  27. def request(query, params):
  28. params['url'] = search_url.format(pageno=params['pageno'],
  29. query=urlencode({'q': query}))
  30. return params
  31. # get response from search-request
  32. def response(resp):
  33. results = []
  34. data_start_pos = resp.text.find('{"filtered"')
  35. data_end_pos = resp.text.find(';\n', data_start_pos + 1)
  36. data = loads(resp.text[data_start_pos:data_end_pos])
  37. # parse results
  38. for result in data['filtered']['data']:
  39. result = result[result['type']]
  40. videoid = result['uri'].split('/')[-1]
  41. url = base_url + videoid
  42. title = result['name']
  43. thumbnail = result['pictures']['sizes'][-1]['link']
  44. publishedDate = parser.parse(result['created_time'])
  45. embedded = embedded_url.format(videoid=videoid)
  46. # append result
  47. results.append({'url': url,
  48. 'title': title,
  49. 'content': '',
  50. 'template': 'videos.html',
  51. 'publishedDate': publishedDate,
  52. 'embedded': embedded,
  53. 'thumbnail': thumbnail})
  54. # return results
  55. return results