'Handles updating KODI host via HTTP JSON-RPC
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_json(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    JSON    method    for    host:    ' + host))
    if showName:
        showName = urllib.unquote_plus(showName)
        tvshowid = (-1)
        path = u''
        sickrage.srCore.srLogger.debug((u'Updating    library    in    KODI    via    JSON    method    for    show    ' + showName))
        showsCommand = u'{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShows","params":{"filter":{"field":"title","operator":"is","value":"%s"},"properties":["title"]},"id":"SiCKRAGE"}'
        showsResponse = self._send_to_kodi_json((showsCommand % showName), host)
        if (showsResponse and (u'result' in showsResponse) and (u'tvshows' in showsResponse[u'result'])):
            shows = showsResponse[u'result'][u'tvshows']
        else:
            showsCommand = u'{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShows","id":1}'
            showsResponse = self._send_to_kodi_json(showsCommand, host)
            if (showsResponse and (u'result' in showsResponse) and (u'tvshows' in showsResponse[u'result'])):
                shows = showsResponse[u'result'][u'tvshows']
            else:
                sickrage.srCore.srLogger.debug(u'KODI:    No    tvshows    in    KODI    TV    show    list')
                return False
        for show in shows:
            if (((u'label' in show) and (show[u'label'] == showName)) or ((u'title' in show) and (show[u'title'] == showName))):
                tvshowid = show[u'tvshowid']
                if (u'file' in show):
                    path = show[u'file']
                break
        del shows
        if (tvshowid == (-1)):
            sickrage.srCore.srLogger.debug(u'Exact    show    name    not    matched    in    KODI    TV    show    list')
            return False
        if (not len(path)):
            pathCommand = (u'{"jsonrpc":"2.0","method":"VideoLibrary.GetTVShowDetails","params":{"tvshowid":%d,    "properties":    ["file"]},"id":1}' % tvshowid)
            pathResponse = self._send_to_kodi_json(pathCommand, host)
            path = pathResponse[u'result'][u'tvshowdetails'][u'file']
        sickrage.srCore.srLogger.debug((((((u'Received    Show:    ' + showName) + u'    with    ID:    ') + str(tvshowid)) + u'    Path:    ') + path))
        if (not len(path)):
            sickrage.srCore.srLogger.warning((((((u'No    valid    path    found    for    ' + showName) + u'    with    ID:    ') + str(tvshowid)) + u'    on    ') + host))
            return False
        sickrage.srCore.srLogger.debug((((((u'KODI    Updating    ' + showName) + u'    on    ') + host) + u'    at    ') + path))
        updateCommand = (u'{"jsonrpc":"2.0","method":"VideoLibrary.Scan","params":{"directory":%s},"id":1}' % json.dumps(path))
        request = self._send_to_kodi_json(updateCommand, host)
        if (not request):
            sickrage.srCore.srLogger.warning((((((u'Update    of    show    directory    failed    on    ' + showName) + u'    on    ') + host) + u'    at    ') + path))
            return False
        for r in request:
            if (u'error' in r):
                sickrage.srCore.srLogger.warning((((((u'Error    while    attempting    to    update    show    directory    for    ' + showName) + u'    on    ') + host) + u'    at    ') + path))
                return False
    else:
        sickrage.srCore.srLogger.debug((u'Doing    Full    Library    KODI    update    on    host:    ' + host))
        updateCommand = u'{"jsonrpc":"2.0","method":"VideoLibrary.Scan","id":1}'
        request = self._send_to_kodi_json(updateCommand, host)
        if (not request):
            sickrage.srCore.srLogger.warning((u'KODI    Full    Library    update    failed    on:    ' + host))
            return False
    return True
