Petter Holt Juliussen • Mail | Mastodon | GitHub | Letterboxd

for later reference.

JSON RPC API

2019-04-04

Example

# Imports
import wx
import time
import json
import urllib
from requests import get
from requests.auth import HTTPBasicAuth

# Config
KODI_HOST           = 'localhost'
KODI_PORT           = '8060'
KODI_USER           = 'kodi'
KODI_PASS           = ''
KODI_JSON_URL       = 'http://%s:%s/jsonrpc'
KODI_EXODUS_SEARCH  = {'jsonrpc': '2.0', 
                        'id': 2, 
                        'method': 
                        'Addons.ExecuteAddon', 
                        'params': {
                            'wait': False, 
                            'addonid': 'plugin.video.exodus', 
                            'params': {
                                'action': 'movieSearch', 
                                'query': ''
                            }
                        }
                    }

# Request
def request(json_request):
    payload = {'request': json.dumps(json_request)}
    auth = HTTPBasicAuth(KODI_USER, KODI_PASS)
    r = get(KODI_JSON_URL % (KODI_HOST, KODI_PORT), params=payload, auth=auth)

    if r.status_code == 200:
        print r.json()
    elif r.status_code == 400:
        print '401: Unauthorized'
    else:
        print 'Error: %d' % (r.status_code)


# Search
def exodus_search(title):
    KODI_EXODUS_SEARCH['params']['params']['query'] = title.replace('\'', '')
    return request(KODI_EXODUS_SEARCH)


# Main
if __name__ == '__main__':
    exodus_search('in bruges')