Fix getting new pms_identifier for server only

This commit is contained in:
JonnyWong16 2016-02-02 20:33:47 -08:00
parent a957e8eb4f
commit 36de20dd75

View file

@ -383,7 +383,6 @@ class PlexTV(object):
return [] return []
plextv_resources = self.get_plextv_resources(include_https=include_https) plextv_resources = self.get_plextv_resources(include_https=include_https)
server_urls = []
try: try:
xml_parse = minidom.parseString(plextv_resources) xml_parse = minidom.parseString(plextv_resources)
@ -400,36 +399,51 @@ class PlexTV(object):
logger.warn(u"PlexPy PlexTV :: Unable to parse XML for get_server_urls: %s." % e) logger.warn(u"PlexPy PlexTV :: Unable to parse XML for get_server_urls: %s." % e)
return [] return []
# Function to get all connections for a device
def get_connections(device):
conn = []
connections = device.getElementsByTagName('Connection')
for c in connections:
server_details = {"protocol": helpers.get_xml_attr(c, 'protocol'),
"address": helpers.get_xml_attr(c, 'address'),
"port": helpers.get_xml_attr(c, 'port'),
"uri": helpers.get_xml_attr(c, 'uri'),
"local": helpers.get_xml_attr(c, 'local')
}
conn.append(server_details)
return conn
server_urls = []
# Try to match the device
for a in xml_head: for a in xml_head:
if helpers.get_xml_attr(a, 'clientIdentifier') == server_id: if helpers.get_xml_attr(a, 'clientIdentifier') == server_id:
connections = a.getElementsByTagName('Connection') server_urls = get_connections(a)
for connection in connections: break
server_details = {"protocol": helpers.get_xml_attr(connection, 'protocol'),
"address": helpers.get_xml_attr(connection, 'address'),
"port": helpers.get_xml_attr(connection, 'port'),
"uri": helpers.get_xml_attr(connection, 'uri'),
"local": helpers.get_xml_attr(connection, 'local')
}
server_urls.append(server_details) # Else no device match found
# Else try to match the PMS_IP and PMS_PORT if not server_urls:
else: # Try to match the PMS_IP and PMS_PORT
connections = a.getElementsByTagName('Connection') for a in xml_head:
for connection in connections: if helpers.get_xml_attr(a, 'provides') == 'server':
if helpers.get_xml_attr(connection, 'address') == plexpy.CONFIG.PMS_IP and \ connections = a.getElementsByTagName('Connection')
int(helpers.get_xml_attr(connection, 'port')) == plexpy.CONFIG.PMS_PORT:
plexpy.CONFIG.PMS_IDENTIFIER = helpers.get_xml_attr(a, 'clientIdentifier') for connection in connections:
if helpers.get_xml_attr(connection, 'address') == plexpy.CONFIG.PMS_IP and \
int(helpers.get_xml_attr(connection, 'port')) == plexpy.CONFIG.PMS_PORT:
logger.info(u"PlexPy PlexTV :: PMS identifier changed from %s to %s." % \ plexpy.CONFIG.PMS_IDENTIFIER = helpers.get_xml_attr(a, 'clientIdentifier')
(server_id, plexpy.CONFIG.PMS_IDENTIFIER)) plexpy.CONFIG.write()
server_details = {"protocol": helpers.get_xml_attr(connection, 'protocol'), logger.info(u"PlexPy PlexTV :: PMS identifier changed from %s to %s." % \
"address": helpers.get_xml_attr(connection, 'address'), (server_id, plexpy.CONFIG.PMS_IDENTIFIER))
"port": helpers.get_xml_attr(connection, 'port'),
"uri": helpers.get_xml_attr(connection, 'uri'), server_urls = get_connections(a)
"local": helpers.get_xml_attr(connection, 'local') break
}
if server_urls:
break break
return server_urls return server_urls