From 5043c3401203786fc92a2893fc5b6f3feadc9715 Mon Sep 17 00:00:00 2001 From: Erin Morelli Date: Mon, 10 Oct 2016 15:57:14 -0400 Subject: [PATCH 1/2] Addressing incorrect server issue (#2) --- plex_updater.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/plex_updater.py b/plex_updater.py index d3e292c..9fcc289 100755 --- a/plex_updater.py +++ b/plex_updater.py @@ -29,6 +29,10 @@ import subprocess import xml.etree.ElementTree as ET +import pprint +pp = pprint.PrettyPrinter(indent=4) + + # Script global constants API_ROOT_URL = 'https://plex.tv/{0}' @@ -148,7 +152,7 @@ def disable_plex_pass(config): return sign_in_user['authentication_token'] -def get_server_info(token, args): +def get_server_info(token, args, config): ''' Get current server version ''' @@ -163,8 +167,20 @@ def get_server_info(token, args): } ) - # Decode returned XML data - server_xml = ET.fromstring(server_resp.content)[0] + # Get list of Plex servers from XML + server_xml = None + server_resp_xml = ET.fromstring(server_resp.content) + + # Find the server we want to update + for server in server_resp_xml: + if server.get('machineIdentifier') == config['client']: + server_xml = server + break + + # Bail if we didn't find the Plex server we want + if server_xml is None: + msg = 'Could not find a Plex Media Server with client ID: {0}' + sys.exit(msg.format(config['client'])) # Make sure user is server owner if server_xml.get('owned') == '0': @@ -387,7 +403,7 @@ def main(): token = get_token(config) # Get server info - server = get_server_info(token, args) + server = get_server_info(token, args, config) print('Server Version:', server['version'], file=sys.stdout) # Get download info @@ -424,7 +440,7 @@ def main(): sys.exit(msg.format(package)) # Check that install was actually successful - new_server_info = get_server_info(token, args) + new_server_info = get_server_info(token, args, config) # Verify new version if new_server_info['version'] != download['version']: From 9f5f2e256ccec47b961c2b3c30c40c6b7f0030e2 Mon Sep 17 00:00:00 2001 From: Erin Morelli Date: Mon, 10 Oct 2016 16:01:25 -0400 Subject: [PATCH 2/2] Removing leftover debugging code - whoops --- plex_updater.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/plex_updater.py b/plex_updater.py index 9fcc289..10993d8 100755 --- a/plex_updater.py +++ b/plex_updater.py @@ -29,10 +29,6 @@ import subprocess import xml.etree.ElementTree as ET -import pprint -pp = pprint.PrettyPrinter(indent=4) - - # Script global constants API_ROOT_URL = 'https://plex.tv/{0}'