summaryrefslogtreecommitdiff
path: root/searx/engines/mediathekviewweb.py
blob: fa442c9370870fc99e36a3b4be1776bcacfd881b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# SPDX-License-Identifier: AGPL-3.0-or-later
"""MediathekViewWeb (API)

"""

# pylint: disable=missing-function-docstring

import datetime
from json import loads, dumps

about = {
    "website": 'https://mediathekviewweb.de/',
    "wikidata_id": 'Q27877380',
    "official_api_documentation": 'https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de',
    "use_official_api": True,
    "require_api_key": False,
    "results": 'JSON',
}

categories = ['videos']
paging = True
time_range_support = False
safesearch = False

def request(query, params):

    params['url'] = 'https://mediathekviewweb.de/api/query'
    params['method'] = 'POST'
    params['headers']['Content-type'] = 'text/plain'
    params['data'] = dumps({
        'queries' : [
	    {
	        'fields' : [
		    'title',
		    'topic',
	        ],
	    'query' : query
	    },
        ],
        'sortBy' : 'timestamp',
        'sortOrder' : 'desc',
        'future' : True,
        'offset' : (params['pageno'] - 1 )* 10,
        'size' : 10
    })
    return params

def response(resp):

    resp = loads(resp.text)

    mwv_result = resp['result']
    mwv_result_list = mwv_result['results']

    results = []

    for item in mwv_result_list:

        item['hms'] = str(datetime.timedelta(seconds=item['duration']))

        results.append({
            'url' : item['url_video_hd'],
            'title' : "%(channel)s: %(title)s (%(hms)s)" % item,
            'length' : item['hms'],
            'content' : "%(description)s" % item,
        })

    return results