mediathekviewweb.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """MediathekViewWeb (API)
  3. """
  4. import datetime
  5. from json import loads, dumps
  6. about = {
  7. "website": 'https://mediathekviewweb.de/',
  8. "wikidata_id": 'Q27877380',
  9. "official_api_documentation": 'https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de',
  10. "use_official_api": True,
  11. "require_api_key": False,
  12. "results": 'JSON',
  13. "language": "de",
  14. }
  15. categories = ['videos']
  16. paging = True
  17. time_range_support = False
  18. safesearch = False
  19. def request(query, params):
  20. params['url'] = 'https://mediathekviewweb.de/api/query'
  21. params['method'] = 'POST'
  22. params['headers']['Content-type'] = 'text/plain'
  23. params['data'] = dumps(
  24. {
  25. 'queries': [
  26. {
  27. 'fields': [
  28. 'title',
  29. 'topic',
  30. ],
  31. 'query': query,
  32. },
  33. ],
  34. 'sortBy': 'timestamp',
  35. 'sortOrder': 'desc',
  36. 'future': True,
  37. 'offset': (params['pageno'] - 1) * 10,
  38. 'size': 10,
  39. }
  40. )
  41. return params
  42. def response(resp):
  43. resp = loads(resp.text)
  44. mwv_result = resp['result']
  45. mwv_result_list = mwv_result['results']
  46. results = []
  47. for item in mwv_result_list:
  48. item['hms'] = str(datetime.timedelta(seconds=item['duration']))
  49. results.append(
  50. {
  51. 'url': item['url_video_hd'].replace("http://", "https://"),
  52. 'title': "%(channel)s: %(title)s (%(hms)s)" % item,
  53. 'length': item['hms'],
  54. 'content': "%(description)s" % item,
  55. 'iframe_src': item['url_video_hd'].replace("http://", "https://"),
  56. 'template': 'videos.html',
  57. }
  58. )
  59. return results