From 100421ce2de51c0d66ad58a58f4847ec5c6b3024 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Tue, 8 Mar 2016 14:50:43 +0100 Subject: [PATCH] Connect to remote PMS --- resources/lib/PlexAPI.py | 10 +++++----- resources/lib/downloadutils.py | 2 +- resources/lib/initialsetup.py | 30 +++++++++++++++++++----------- resources/lib/userclient.py | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 719e10cb..a68c6014 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -295,13 +295,13 @@ class PlexAPI(): verify=verify, timeout=timeout) except requests.exceptions.ConnectionError as e: - self.logMsg("Server is offline or cannot be reached. Url: %s." - "Header: %s. Error message: %s" - % (url, header, e), -1) + self.logMsg("Server is offline or cannot be reached. Url: %s. " + "Error message: %s" + % (url, e), -1) return False except requests.exceptions.ReadTimeout: - self.logMsg("Server timeout reached for Url %s with header %s" - % (url, header), -1) + self.logMsg("Server timeout reached for Url %s" + % url, -1) return False # We received an answer from the server, but not as expected. if answer.status_code >= 400: diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index e7826709..c53c0664 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -359,7 +359,7 @@ class DownloadUtils(): except requests.exceptions.ConnectionError as e: # Make the addon aware of status if utils.window('emby_online') != "false": - self.logMsg("Server unreachable at: %s" % url, 0) + self.logMsg("Server unreachable at: %s" % url, -1) self.logMsg(e, 2) utils.window('emby_online', value="false") diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 5d69464ce..8fa55c92 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -44,7 +44,7 @@ class InitialSetup(): plexLogin = plexdict['plexLogin'] plexToken = plexdict['plexToken'] plexid = plexdict['plexid'] - self.logMsg('Plex info retrieved from settings: %s' % plexdict, 1) + self.logMsg('Plex info retrieved from settings', 1) dialog = xbmcgui.Dialog() @@ -120,8 +120,13 @@ class InitialSetup(): resp = dialog.select(string(39012), dialoglist) server = serverlist[resp] activeServer = server['machineIdentifier'] - url = server['scheme'] + '://' + server['ip'] + ':' + \ - server['port'] + # Re-direct via plex if remote - will lead to the correct SSL + # certificate + if server['local'] == '1': + url = server['scheme'] + '://' + server['ip'] + ':' \ + + server['port'] + else: + url = server['baseURL'] # Deactive SSL verification if the server is local! if server['local'] == '1': utils.settings('sslverify', 'false') @@ -166,18 +171,21 @@ class InitialSetup(): break if not isconnected: # Enter Kodi settings instead - if dialog.yesno( - heading=self.addonName, - line1=string(39016)): - self.logMsg("User opted to disable Plex music library.", 1) - utils.settings('enableMusic', value="false") xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId) return # Write to Kodi settings file utils.settings('plex_machineIdentifier', activeServer) - utils.settings('ipaddress', server['ip']) - utils.settings('port', server['port']) - if server['scheme'] == 'https': + if server['local'] == '1': + scheme = server['scheme'] + utils.settings('ipaddress', server['ip']) + utils.settings('port', server['port']) + else: + baseURL = server['baseURL'].split(':') + scheme = baseURL[0] + utils.settings('ipaddress', baseURL[1].replace('//', '')) + utils.settings('port', baseURL[2]) + + if scheme == 'https': utils.settings('https', 'true') else: utils.settings('https', 'false') diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index ffc7d1e3..3d67ba7a 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -381,7 +381,7 @@ class UserClient(threading.Thread): settings('userId', value="") # Give attempts at entering password / selecting user - if self.retry >= 3: + if self.retry >= 2: log("Too many retries to login.", -1) window('emby_serverStatus', value="Stop") dialog.ok(lang(33001),