ccc_media.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """media.ccc.de"""
  3. import datetime
  4. from urllib.parse import urlencode
  5. from dateutil import parser
  6. about = {
  7. 'website': 'https://media.ccc.de',
  8. 'official_api_documentation': 'https://github.com/voc/voctoweb',
  9. 'use_official_api': True,
  10. 'require_api_key': False,
  11. 'results': 'JSON',
  12. }
  13. categories = ['videos']
  14. paging = True
  15. api_url = "https://api.media.ccc.de"
  16. def request(query, params):
  17. args = {'q': query, 'page': params['pageno']}
  18. params['url'] = f"{api_url}/public/events/search?{urlencode(args)}"
  19. return params
  20. def response(resp):
  21. results = []
  22. for item in resp.json()['events']:
  23. publishedDate = None
  24. if item.get('date'):
  25. publishedDate = parser.parse(item['date'])
  26. iframe_src = None
  27. for rec in item['recordings']:
  28. if rec['mime_type'].startswith('video'):
  29. if not iframe_src:
  30. iframe_src = rec['recording_url']
  31. elif rec['mime_type'] == 'video/mp4':
  32. # prefer mp4 (minimal data rates)
  33. iframe_src = rec['recording_url']
  34. results.append(
  35. {
  36. 'template': 'videos.html',
  37. 'url': item['frontend_link'],
  38. 'title': item['title'],
  39. 'content': item['description'],
  40. 'thumbnail': item['thumb_url'],
  41. 'publishedDate': publishedDate,
  42. 'length': datetime.timedelta(seconds=item['length']),
  43. 'iframe_src': iframe_src,
  44. }
  45. )
  46. return results