'Handles communication to KODI servers via JSONRPC
Args:
command: Dictionary of field/data pairs, encoded via urllib and passed to the KODI JSON-RPC via HTTP
host: KODI webserver host:port
username: KODI webserver username
password: KODI webserver password
Returns:
Returns response.result for successful commands or False if there was an error'

def _send_to_kodi_json(self, command, host=None, username=None, password=None):

    if (not username):
        username = sickrage.srCore.srConfig.KODI_USERNAME
    if (not password):
        password = sickrage.srCore.srConfig.KODI_PASSWORD
    if (not host):
        sickrage.srCore.srLogger.warning(u'No    KODI    host    passed,    aborting    update')
        return False
    command = command.encode(u'utf-8')
    sickrage.srCore.srLogger.debug((u'KODI    JSON    command:    ' + command))
    url = (u'http://%s/jsonrpc' % host)
    try:
        req = urllib2.Request(url, command)
        req.add_header(u'Content-type', u'application/json')
        if password:
            base64string = base64.encodestring((u'%s:%s' % (username, password)))[:(-1)]
            authheader = (u'Basic    %s' % base64string)
            req.add_header(u'Authorization', authheader)
            sickrage.srCore.srLogger.debug((u'Contacting    KODI    (with    auth    header)    via    url:    ' + url))
        else:
            sickrage.srCore.srLogger.debug((u'Contacting    KODI    via    url:    ' + url))
        try:
            response = urllib2.urlopen(req)
        except (httplib.BadStatusLine, urllib2.URLError) as e:
            if sickrage.srCore.srConfig.KODI_ALWAYS_ON:
                sickrage.srCore.srLogger.warning(((u'Error    while    trying    to    retrieve    KODI    API    version    for    ' + host) + u':    {}'.format(e.message)))
            return False
        try:
            result = json.load(response)
            response.close()
            sickrage.srCore.srLogger.debug((u'KODI    JSON    response:    ' + str(result)))
            return result
        except ValueError as e:
            sickrage.srCore.srLogger.warning((u'Unable    to    decode    JSON:    ' + str(response.read())))
            return False
    except IOError as e:
        if sickrage.srCore.srConfig.KODI_ALWAYS_ON:
            sickrage.srCore.srLogger.warning(((u"Warning:    Couldn't    contact    KODI    JSON    API    at    " + url) + u'    {}'.format(e.message)))
        return False
