tvmaze.py 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """
  2. TVmaze
  3. Show Search
  4. """
  5. from urllib.parse import urlencode
  6. from json import loads
  7. from searx.utils import html_to_text
  8. # about
  9. about = {
  10. "website": 'https://www.tvmaze.com/',
  11. "wikidata_id": 'Q84863617',
  12. "official_api_documentation": 'https://www.tvmaze.com/api',
  13. "use_official_api": True,
  14. "require_api_key": False,
  15. "results": 'JSON',
  16. }
  17. categories = ['general']
  18. paging = False
  19. # search-url
  20. base_url = 'https://api.tvmaze.com/search/'
  21. search_string = 'shows?{query}'
  22. def request(query, params):
  23. search = search_string.format(query=urlencode({'q': query}))
  24. params['url'] = base_url + search
  25. return params
  26. def response(resp):
  27. results = []
  28. search_res = loads(resp.text)
  29. for result in search_res:
  30. res = result['show']
  31. results.append({
  32. 'url': res['url'],
  33. 'title': res['name'],
  34. 'content': html_to_text(res['summary'] or "")
  35. })
  36. return results