mediathekviewweb.py 1.8 KB

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