From cad59235466b50682adbb783613339274b1b6a0d Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 21 Feb 2020 09:12:59 +0100 Subject: [PATCH] Improve logic to connect to local PMS via plex.direct redirect --- resources/lib/plex_functions.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/resources/lib/plex_functions.py b/resources/lib/plex_functions.py index c9e29491..045d1a5f 100644 --- a/resources/lib/plex_functions.py +++ b/resources/lib/plex_functions.py @@ -210,24 +210,31 @@ def discover_pms(token=None): if pms['machineIdentifier'] == plex_pms['machineIdentifier']: break else: - # Only found PMS using GDM - add it to the PMS from plex.tv - https = _pms_https_enabled('%s:%s' % (pms['ip'], pms['port'])) - if https is None: - # Error contacting url. Skip and ignore this PMS for now - LOG.error('Could not contact PMS %s but we should have', pms) - continue - elif https is True: - pms['scheme'] = 'https' - else: - pms['scheme'] = 'http' - pms['baseURL'] = '%s://%s:%s' % (pms['scheme'], - pms['ip'], - pms['port']) + # Only found PMS using GDM. Check whether we can use baseURL + # (which is in a different format) or need to connect directly + if not _correct_baseurl(pms, + '%s:%s' % (pms['baseURL'], pms['port'])): + if not _correct_baseurl(pms, + '%s:%s' % (pms['ip'], pms['port'])): + continue plex_pms_list.append(pms) _log_pms(plex_pms_list) return plex_pms_list +def _correct_baseurl(pms, url): + https = _pms_https_enabled(url) + if https is None: + # Error contacting url + return False + elif https is True: + pms['scheme'] = 'https' + else: + pms['scheme'] = 'http' + pms['baseURL'] = '%s://%s' % (pms['scheme'], url) + return True + + def _log_pms(pms_list): log_list = deepcopy(pms_list) for pms in log_list: