'Handles updating KODI host via HTTP API
Attempts to update the KODI video library for a specific tv show if passed,
otherwise update the whole library if enabled.
Args:
host: KODI webserver host:port
showName: Name of a TV show to specifically target the library update for
Returns:
Returns True or False'

def _update_library(self, host=None, showName=None):

    if (not host):
        sickrage.srCore.srLogger.warning(u'No    KODI    host    passed,    aborting    update')
        return False
    sickrage.srCore.srLogger.debug((u'Updating    KODI    library    via    HTTP    method    for    host:    ' + host))
    if showName:
        sickrage.srCore.srLogger.debug((u'Updating    library    in    KODI    via    HTTP    method    for    show    ' + showName))
        pathSql = u'select    path.strPath    from    path,    tvshow,    tvshowlinkpath    where    tvshow.c00    =    "{0:s}"    and    tvshowlinkpath.idShow    =    tvshow.idShow    and    tvshowlinkpath.idPath    =    path.idPath'.format(showName)
        xmlCommand = {u'command': u'SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)'}
        sqlCommand = {u'command': (u'QueryVideoDatabase(%s)' % pathSql)}
        resetCommand = {u'command': u'SetResponseFormat()'}
        request = self._send_to_kodi(xmlCommand, host)
        if (not request):
            return False
        sqlXML = self._send_to_kodi(sqlCommand, host)
        request = self._send_to_kodi(resetCommand, host)
        if (not sqlXML):
            sickrage.srCore.srLogger.debug((((u'Invalid    response    for    ' + showName) + u'    on    ') + host))
            return False
        encSqlXML = urllib.quote(sqlXML, u':\\/<>')
        try:
            et = ElementTree.fromstring(encSqlXML)
        except SyntaxError as e:
            sickrage.srCore.srLogger.error(u'Unable    to    parse    XML    returned    from    KODI:    {}'.format(e.message))
            return False
        paths = et.findall(u'.//field')
        if (not paths):
            sickrage.srCore.srLogger.debug((((u'No    valid    paths    found    for    ' + showName) + u'    on    ') + host))
            return False
        for path in paths:
            unEncPath = urllib.unquote(path.text).decode(sickrage.SYS_ENCODING)
            sickrage.srCore.srLogger.debug((((((u'KODI    Updating    ' + showName) + u'    on    ') + host) + u'    at    ') + unEncPath))
            updateCommand = {u'command': u'ExecBuiltIn', u'parameter': (u'KODI.updatelibrary(video,    %s)' % unEncPath)}
            request = self._send_to_kodi(updateCommand, host)
            if (not request):
                sickrage.srCore.srLogger.warning((((((u'Update    of    show    directory    failed    on    ' + showName) + u'    on    ') + host) + u'    at    ') + unEncPath))
                return False
            if (len(paths) > 1):
                time.sleep(5)
    else:
        sickrage.srCore.srLogger.debug((u'Doing    Full    Library    KODI    update    on    host:    ' + host))
        updateCommand = {u'command': u'ExecBuiltIn', u'parameter': u'KODI.updatelibrary(video)'}
        request = self._send_to_kodi(updateCommand, host)
        if (not request):
            sickrage.srCore.srLogger.warning((u'KODI    Full    Library    update    failed    on:    ' + host))
            return False
    return True
