Improve logic to connect to local PMS via plex.direct redirect

This commit is contained in:
croneter 2020-02-21 09:12:59 +01:00
parent 83598ff3f1
commit cad5923546

View file

@ -210,22 +210,29 @@ def discover_pms(token=None):
if pms['machineIdentifier'] == plex_pms['machineIdentifier']: if pms['machineIdentifier'] == plex_pms['machineIdentifier']:
break break
else: else:
# Only found PMS using GDM - add it to the PMS from plex.tv # Only found PMS using GDM. Check whether we can use baseURL
https = _pms_https_enabled('%s:%s' % (pms['ip'], pms['port'])) # (which is in a different format) or need to connect directly
if https is None: if not _correct_baseurl(pms,
# Error contacting url. Skip and ignore this PMS for now '%s:%s' % (pms['baseURL'], pms['port'])):
LOG.error('Could not contact PMS %s but we should have', pms) if not _correct_baseurl(pms,
'%s:%s' % (pms['ip'], pms['port'])):
continue 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: elif https is True:
pms['scheme'] = 'https' pms['scheme'] = 'https'
else: else:
pms['scheme'] = 'http' pms['scheme'] = 'http'
pms['baseURL'] = '%s://%s:%s' % (pms['scheme'], pms['baseURL'] = '%s://%s' % (pms['scheme'], url)
pms['ip'], return True
pms['port'])
plex_pms_list.append(pms)
_log_pms(plex_pms_list)
return plex_pms_list
def _log_pms(pms_list): def _log_pms(pms_list):