mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Discover localhost server
This commit is contained in:
parent
e567134ee1
commit
ab5384cfdf
5 changed files with 114 additions and 33 deletions
|
@ -685,6 +685,23 @@ class PlexTV(object):
|
|||
|
||||
def discover(self, include_cloud=True, all_servers=False):
|
||||
""" Query plex for all servers online. Returns the ones you own in a selectize format """
|
||||
|
||||
# Try to discover localhost server
|
||||
pms_connect = pmsconnect.PmsConnect(url='http://127.0.0.1:32400')
|
||||
pms_connect.request_handler.timeout = 1
|
||||
identity = pms_connect.get_server_identity(log=False)
|
||||
local_machine_identifier = identity.get('machine_identifier')
|
||||
local_server = {'httpsRequired': '0',
|
||||
'clientIdentifier': local_machine_identifier,
|
||||
'label': 'Local',
|
||||
'ip': '127.0.0.1',
|
||||
'port': '32400',
|
||||
'uri': 'http://127.0.0.1:32400',
|
||||
'local': '1',
|
||||
'value': '127.0.0.1:32400',
|
||||
'is_cloud': False
|
||||
}
|
||||
|
||||
servers = self.get_plextv_resources(include_https=True, output_format='xml')
|
||||
clean_servers = []
|
||||
|
||||
|
@ -704,8 +721,8 @@ class PlexTV(object):
|
|||
|
||||
for d in devices:
|
||||
if helpers.get_xml_attr(d, 'presence') == '1' and \
|
||||
helpers.get_xml_attr(d, 'owned') == '1' and \
|
||||
helpers.get_xml_attr(d, 'provides') == 'server':
|
||||
helpers.get_xml_attr(d, 'owned') == '1' and \
|
||||
helpers.get_xml_attr(d, 'provides') == 'server':
|
||||
|
||||
is_cloud = (helpers.get_xml_attr(d, 'platform').lower() == 'cloud')
|
||||
if not include_cloud and is_cloud:
|
||||
|
@ -717,14 +734,20 @@ class PlexTV(object):
|
|||
if not all_servers:
|
||||
# If this is a remote server don't show any local IPs.
|
||||
if helpers.get_xml_attr(d, 'publicAddressMatches') == '0' and \
|
||||
helpers.get_xml_attr(c, 'local') == '1':
|
||||
helpers.get_xml_attr(c, 'local') == '1':
|
||||
continue
|
||||
|
||||
# If this is a local server don't show any remote IPs.
|
||||
if helpers.get_xml_attr(d, 'publicAddressMatches') == '1' and \
|
||||
helpers.get_xml_attr(c, 'local') == '0':
|
||||
helpers.get_xml_attr(c, 'local') == '0':
|
||||
continue
|
||||
|
||||
if helpers.get_xml_attr(d, 'clientIdentifier') == local_machine_identifier:
|
||||
local_server['httpsRequired'] = helpers.get_xml_attr(d, 'httpsRequired')
|
||||
local_server['label'] = helpers.get_xml_attr(d, 'name')
|
||||
clean_servers.append(local_server)
|
||||
local_machine_identifier = None
|
||||
|
||||
server = {'httpsRequired': '1' if is_cloud else helpers.get_xml_attr(d, 'httpsRequired'),
|
||||
'clientIdentifier': helpers.get_xml_attr(d, 'clientIdentifier'),
|
||||
'label': helpers.get_xml_attr(d, 'name'),
|
||||
|
@ -732,11 +755,16 @@ class PlexTV(object):
|
|||
'port': helpers.get_xml_attr(c, 'port'),
|
||||
'uri': helpers.get_xml_attr(c, 'uri'),
|
||||
'local': helpers.get_xml_attr(c, 'local'),
|
||||
'value': helpers.get_xml_attr(c, 'address'),
|
||||
'value': helpers.get_xml_attr(c, 'address') + ':' + helpers.get_xml_attr(c, 'port'),
|
||||
'is_cloud': is_cloud
|
||||
}
|
||||
clean_servers.append(server)
|
||||
|
||||
if local_machine_identifier:
|
||||
clean_servers.append(local_server)
|
||||
|
||||
clean_servers.sort(key=lambda s: (s['label'], -int(s['local']), s['ip']))
|
||||
|
||||
return clean_servers
|
||||
|
||||
def get_plex_downloads(self):
|
||||
|
|
|
@ -2193,7 +2193,7 @@ class PmsConnect(object):
|
|||
|
||||
return server_info
|
||||
|
||||
def get_server_identity(self):
|
||||
def get_server_identity(self, log=True):
|
||||
"""
|
||||
Return the local machine identity.
|
||||
|
||||
|
@ -2204,7 +2204,8 @@ class PmsConnect(object):
|
|||
try:
|
||||
xml_head = identity.getElementsByTagName('MediaContainer')
|
||||
except Exception as e:
|
||||
logger.warn(u"Tautulli Pmsconnect :: Unable to parse XML for get_local_server_identity: %s." % e)
|
||||
if log:
|
||||
logger.warn(u"Tautulli Pmsconnect :: Unable to parse XML for get_local_server_identity: %s." % e)
|
||||
return {}
|
||||
|
||||
server_identity = {}
|
||||
|
|
|
@ -110,6 +110,7 @@ class WebInterface(object):
|
|||
"pms_is_cloud": plexpy.CONFIG.PMS_IS_CLOUD,
|
||||
"pms_token": plexpy.CONFIG.PMS_TOKEN,
|
||||
"pms_uuid": plexpy.CONFIG.PMS_UUID,
|
||||
"pms_name": plexpy.CONFIG.PMS_NAME,
|
||||
"logging_ignore_interval": plexpy.CONFIG.LOGGING_IGNORE_INTERVAL
|
||||
}
|
||||
|
||||
|
@ -2802,6 +2803,7 @@ class WebInterface(object):
|
|||
"pms_url_manual": checked(plexpy.CONFIG.PMS_URL_MANUAL),
|
||||
"pms_uuid": plexpy.CONFIG.PMS_UUID,
|
||||
"pms_web_url": plexpy.CONFIG.PMS_WEB_URL,
|
||||
"pms_name": plexpy.CONFIG.PMS_NAME,
|
||||
"date_format": plexpy.CONFIG.DATE_FORMAT,
|
||||
"time_format": plexpy.CONFIG.TIME_FORMAT,
|
||||
"week_start_monday": checked(plexpy.CONFIG.WEEK_START_MONDAY),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue