mediathekview / mediathekviewweb

Eine Weboberfläche als Alternative zum Java-Client
https://mediathekviewweb.de/
GNU General Public License v3.0
887 stars 67 forks source link

get links by api? #164

Closed ezzra closed 3 years ago

ezzra commented 4 years ago

is there already a way to request the data via an api link, for example as json output? I know the apps goal is to be a webfrontend, but as the data is there it would be nice to fetch it this way too :)

bagbag commented 4 years ago

Take a look at this: https://gist.github.com/bagbag/a2888478d27de0e989cf777f81fb33de

faulesocke commented 3 years ago

Does this need any special headers normally only sent by browsers? I tried replicating this using python (should be a no-brainer) but I always get error messages from the server saying:

 {'result': None, 'err': ['Unexpected token o in JSON at position 1']}

Code:

import requests

url = "https://mediathekviewweb.de/api/query"
query = {
    "queries": [
        {
            "fields": ["title", "topic"],
            "query": "sturm der liebe",
        },
    ],
    "sortBy": "timestamp",
    "sortOrder": "desc",
    "future": True,
    "offset": 0,
    "size": 10,
}

#query = """{"queries":[{"fields":["title","topic"],"query":"sturm der liebe"},{"fields":["channel"],"query":"ndr"}],"sortBy":"timestamp","sortOrder":"desc","future":false,"offset":0,"size":10}"""

res = requests.post(url, json=query)
req = res.request
req.body, res.json()

I'm sure I did something stupidly wrong but I can't find what. :/

bagbag commented 3 years ago

Thats actually not a problem on your side, but on mine. Use the header "Content-Type: text/plain" and it should work.

MrFly72 commented 3 years ago

I had the problem that not all airings would be delivered back. Found my problem. I had to increase the size for specific entries, as the result of the query is too big. Omitted the size, but I dont know whats the default ??? If someone is interested in how to query with powershell:

$MediathekQuery = @{
    queries = @(
        @{fields = "topic"; query = "Filme im Ersten" }
        @{fields = "channel"; query = "ard" }
    )
    sortBy = "timestamp"; sortOrder = "desc"; future = $future; size = 30
}
$headers = @{
    "Content-Type" = "text/plain"
}
$QueryJSON = $MediathekQuery | ConvertTo-Json -Depth 20 -Compress
$Answer = Invoke-RestMethod -Method Post -Uri "https://mediathekviewweb.de/api/query" -Headers $headers -Body $QueryJSON -Verbose
$Answer.result.results #Output the results