mediathekviewweb.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """MediathekViewWeb (API)
  4. """
  5. # pylint: disable=missing-function-docstring
  6. import datetime
  7. from json import loads, dumps
  8. about = {
  9. "website": 'https://mediathekviewweb.de/',
  10. "wikidata_id": 'Q27877380',
  11. "official_api_documentation": 'https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de',
  12. "use_official_api": True,
  13. "require_api_key": False,
  14. "results": 'JSON',
  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. '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. return params
  41. def response(resp):
  42. resp = loads(resp.text)
  43. mwv_result = resp['result']
  44. mwv_result_list = mwv_result['results']
  45. results = []
  46. for item in mwv_result_list:
  47. item['hms'] = str(datetime.timedelta(seconds=item['duration']))
  48. results.append({
  49. 'url' : item['url_video_hd'],
  50. 'title' : "%(channel)s: %(title)s (%(hms)s)" % item,
  51. 'length' : item['hms'],
  52. 'content' : "%(description)s" % item,
  53. })
  54. return results