'Handles updating the Plex Media Server host via HTTP API
Plex Media Server currently only supports updating the whole video library and not a specific path.
Returns:
Returns None for no issue, else a string of host with connection issues'

def update_library(self, ep_obj=None, host=None, username=None, password=None, plex_server_token=None, force=False):

    if ((not (sickbeard.USE_PLEX_SERVER and sickbeard.PLEX_UPDATE_LIBRARY)) and (not force)):
        return None
    host = (host or sickbeard.PLEX_SERVER_HOST)
    if (not host):
        logger.log(u'PLEX:    No    Plex    Media    Server    host    specified,    check    your    settings', logger.DEBUG)
        return False
    if (not self.get_token(username, password, plex_server_token)):
        logger.log(u'PLEX:    Error    getting    auth    token    for    Plex    Media    Server,    check    your    settings', logger.WARNING)
        return False
    file_location = (u'' if (not ep_obj) else ep_obj.location)
    host_list = {x.strip() for x in host.split(u',') if x.strip()}
    hosts_all = hosts_match = {}
    hosts_failed = set()
    for cur_host in host_list:
        url = u'http{0}://{1}/library/sections'.format((u'', u's')[sickbeard.PLEX_SERVER_HTTPS], cur_host)
        try:
            xml_response = getURL(url, headers=self.headers, session=self.session, returns=u'text', verify=False, allow_proxy=False)
            if (not xml_response):
                logger.log(u'PLEX:    Error    while    trying    to    contact    Plex    Media    Server:    {0}'.format(cur_host), logger.WARNING)
                hosts_failed.add(cur_host)
                continue
            media_container = etree.fromstring(xml_response)
        except IOError as error:
            logger.log(u'PLEX:    Error    while    trying    to    contact    Plex    Media    Server:    {0}'.format(ex(error)), logger.WARNING)
            hosts_failed.add(cur_host)
            continue
        except Exception as error:
            if (u'invalid    token' in str(error)):
                logger.log(u'PLEX:    Please    set    TOKEN    in    Plex    settings:    ', logger.WARNING)
            else:
                logger.log(u'PLEX:    Error    while    trying    to    contact    Plex    Media    Server:    {0}'.format(ex(error)), logger.WARNING)
            hosts_failed.add(cur_host)
            continue
        sections = media_container.findall(u'.//Directory')
        if (not sections):
            logger.log(u'PLEX:    Plex    Media    Server    not    running    on:    {0}'.format(cur_host), logger.DEBUG)
            hosts_failed.add(cur_host)
            continue
        for section in sections:
            if (u'show' == section.attrib[u'type']):
                keyed_host = [(str(section.attrib[u'key']), cur_host)]
                hosts_all.update(keyed_host)
                if (not file_location):
                    continue
                for section_location in section.findall(u'.//Location'):
                    section_path = re.sub(u'[/\\\\]+', u'/', section_location.attrib[u'path'].lower())
                    section_path = re.sub(u'^(.{,2})[/\\\\]', u'', section_path)
                    location_path = re.sub(u'[/\\\\]+', u'/', file_location.lower())
                    location_path = re.sub(u'^(.{,2})[/\\\\]', u'', location_path)
                    if (section_path in location_path):
                        hosts_match.update(keyed_host)
    if force:
        return (u',    '.join(set(hosts_failed)), None)[(not len(hosts_failed))]
    if hosts_match:
        logger.log((u'PLEX:    Updating    hosts    where    TV    section    paths    match    the    downloaded    show:    ' + u',    '.join(set(hosts_match))), logger.DEBUG)
    else:
        logger.log((u'PLEX:    Updating    all    hosts    with    TV    sections:    ' + u',    '.join(set(hosts_all))), logger.DEBUG)
    hosts_try = (hosts_match.copy(), hosts_all.copy())[(not len(hosts_match))]
    for (section_key, cur_host) in six.iteritems(hosts_try):
        url = u'http{0}://{1}/library/sections/{2}/refresh'.format((u'', u's')[sickbeard.PLEX_SERVER_HTTPS], cur_host, section_key)
        try:
            getURL(url, headers=self.headers, session=self.session, returns=u'text', verify=False, allow_proxy=False)
        except Exception as error:
            logger.log(u'PLEX:    Error    updating    library    section    for    Plex    Media    Server:    {0}'.format(ex(error)), logger.WARNING)
            hosts_failed.add(cur_host)
    return (u',    '.join(set(hosts_failed)), None)[(not len(hosts_failed))]
