'Handles communication to KODI servers via HTTP API
Args:
command: Dictionary of field/data pairs, encoded via urllib and passed to the KODI API 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(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
    for key in command:
        if isinstance(command[key], six.text_type):
            command[key] = command[key].encode(u'utf-8')
    enc_command = urllib.parse.urlencode(command)
    logger.log(u'{0}    encoded    API    command:    {1!r}'.format(dest_app, enc_command), logger.DEBUG)
    url = u'http://{0}/kodiCmds/kodiHttp/?{1}'.format(host, enc_command)
    try:
        req = urllib.request.Request(url)
        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:
            logger.log(u"Couldn't    contact    {0}    HTTP    at    {1!r}    :    {2!r}".format(dest_app, url, ex(e)), logger.DEBUG)
            return False
        result = response.read().decode(sickbeard.SYS_ENCODING)
        response.close()
        logger.log(u'{0}    HTTP    response:    {1}'.format(dest_app, result.replace(u'\n', u'')), logger.DEBUG)
        return result
    except Exception as e:
        logger.log(u"Couldn't    contact    {0}    HTTP    at    {1!r}    :    {2!r}".format(dest_app, url, ex(e)), logger.DEBUG)
        return False
