podcastindex.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """Podcast Index
  3. """
  4. from urllib.parse import quote_plus
  5. from datetime import datetime
  6. about = {
  7. 'website': 'https://podcastindex.org',
  8. 'official_api_documentation': None, # requires an account
  9. 'use_official_api': False,
  10. 'require_api_key': False,
  11. 'results': 'JSON',
  12. }
  13. categories = []
  14. base_url = "https://podcastindex.org"
  15. def request(query, params):
  16. params['url'] = f"{base_url}/api/search/byterm?q={quote_plus(query)}"
  17. return params
  18. def response(resp):
  19. results = []
  20. json = resp.json()
  21. for result in json['feeds']:
  22. results.append(
  23. {
  24. 'url': result['link'],
  25. 'title': result['title'],
  26. 'content': result['description'],
  27. 'thumbnail': result['image'],
  28. 'publishedDate': datetime.utcfromtimestamp(result['newestItemPubdate']),
  29. 'metadata': f"{result['author']}, {result['episodeCount']} episodes",
  30. }
  31. )
  32. return results