'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'

@staticmethod
def _send_to_kodi_json(command, host=None, username=None, password=None, dest_app=u'KODI'):

    if (not username):
        username = sickbeard.KODI_USERNAME
    if (not password):
        password = sickbeard.KODI_PASSWORD
    if (not host):
        logger.log(u'No    {0}    host    passed,    aborting    update'.format(dest_app), logger.WARNING)
        return False
    command = command.encode(u'utf-8')
    logger.log(u'{0}    JSON    command:    {1}'.format(dest_app, command), logger.DEBUG)
    url = u'http://{0}/jsonrpc'.format(host)
    try:
        req = urllib.request.Request(url, command)
        req.add_header(u'Content-type', u'application/json')
        if password:
            base64string = base64.encodestring(u'{0}:{1}'.format(username, password))[:(-1)]
            authheader = u'Basic    {0}'.format(base64string)
            req.add_header(u'Authorization', authheader)
            logger.log(u'Contacting    {0}    (with    auth    header)    via    url:    {1}'.format(dest_app, ss(url)), logger.DEBUG)
        else:
            logger.log(u'Contacting    {0}    via    url:    {1}'.format(dest_app, ss(url)), logger.DEBUG)
        try:
            response = urllib.request.urlopen(req)
        except (http_client.BadStatusLine, urllib.error.URLError) as e:
            if sickbeard.KODI_ALWAYS_ON:
                logger.log(u'Error    while    trying    to    retrieve    {0}    API    version    for    {1}:    {2!r}'.format(dest_app, host, ex(e)), logger.WARNING)
            return False
        try:
            result = json.load(response)
            response.close()
            logger.log(u'{0}    JSON    response:    {1}'.format(dest_app, result), logger.DEBUG)
            return result
        except ValueError as e:
            logger.log((u'Unable    to    decode    JSON:    ' + str(response.read())), logger.WARNING)
            return False
    except IOError as e:
        if sickbeard.KODI_ALWAYS_ON:
            logger.log(u"Warning:    Couldn't    contact    {0}    JSON    API    at    {1}:    {2!r}".format(dest_app, ss(url), ex(e)), logger.WARNING)
        return False
