vimeo.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. Wikipedia (Web
  4. """
  5. from urllib.parse import urlencode
  6. from json import loads
  7. from dateutil import parser
  8. # about
  9. about = {
  10. "website": 'https://vimeo.com/',
  11. "wikidata_id": 'Q156376',
  12. "official_api_documentation": 'http://developer.vimeo.com/api',
  13. "use_official_api": False,
  14. "require_api_key": False,
  15. "results": 'HTML',
  16. }
  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="https://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