From f290372c5deb87edf623bf6f99a0665bd9412b4d Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Sat, 15 Aug 2015 00:20:06 -0500 Subject: [PATCH] Added permanent users When starting the Kodi session, will automatically add users to the session. --- resources/lib/DownloadUtils.py | 19 +++++++++++++++++++ resources/lib/Entrypoint.py | 5 +++-- resources/lib/UserClient.py | 8 ++++++++ resources/settings.xml | 1 + service.py | 8 +++++++- 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/resources/lib/DownloadUtils.py b/resources/lib/DownloadUtils.py index 177db42d..74995c38 100644 --- a/resources/lib/DownloadUtils.py +++ b/resources/lib/DownloadUtils.py @@ -106,6 +106,25 @@ class DownloadUtils(): self.WINDOW.setProperty("sessionId%s" % self.username, sessionId) except: self.logMsg("Failed to retrieve sessionId.", 1) + else: + # Post any permanent additional users + additionalUsers = utils.settings('additionalUsers').split(',') + self.logMsg("List of permanent users that should be added to the session: %s" % str(additionalUsers), 1) + # Get the user list from server to get the userId + url = "{server}/mediabrowser/Users?format=json" + result = self.downloadUrl(url) + + if result: + for user in result: + username = user['Name'].lower() + userId = user['Id'] + for additional in additionalUsers: + addUser = additional.decode('utf-8').lower() + if username in addUser: + url = "{server}/mediabrowser/Sessions/%s/Users/%s" % (sessionId, userId) + postdata = {} + self.downloadUrl(url, postBody=postdata, type="POST") + #xbmcgui.Dialog().notification("Success!", "%s added to viewing session" % username, time=1000) def startSession(self): diff --git a/resources/lib/Entrypoint.py b/resources/lib/Entrypoint.py index 52937421..6e10a414 100644 --- a/resources/lib/Entrypoint.py +++ b/resources/lib/Entrypoint.py @@ -98,8 +98,9 @@ def addUser(): elif option == 0: # User selected Add user for adduser in additionalUsername: - xbmc.log(str(adduser)) - users.remove(adduser) + try: # Remove from selected already added users. It is possible they are hidden. + users.remove(adduser) + except: pass elif option < 0: # User cancelled diff --git a/resources/lib/UserClient.py b/resources/lib/UserClient.py index 1764591e..b0a507f4 100644 --- a/resources/lib/UserClient.py +++ b/resources/lib/UserClient.py @@ -64,6 +64,13 @@ class UserClient(threading.Thread): return username + def getAdditionalUsers(self): + + additionalUsers = utils.settings('additionalUsers') + + if additionalUsers: + self.AdditionalUser = additionalUsers.split(',') + def getLogLevel(self): try: @@ -251,6 +258,7 @@ class UserClient(threading.Thread): self.hasAccess() # Start DownloadUtils session doUtils.startSession() + self.getAdditionalUsers() # Set user preferences in settings self.setUserPref() diff --git a/resources/settings.xml b/resources/settings.xml index ad857d3c..6317726c 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -39,6 +39,7 @@ + diff --git a/service.py b/service.py index 042d0505..0506f741 100644 --- a/service.py +++ b/service.py @@ -153,7 +153,13 @@ class Service(): if self.welcome_msg: # Reset authentication warnings self.welcome_msg = False - xbmcgui.Dialog().notification("Emby server", "Welcome %s!" % user.currUser, icon="special://home/addons/plugin.video.emby/icon.png", time=2000, sound=False) + # Get additional users + additionalUsers = user.AdditionalUser + if additionalUsers: + add = ", %s" % ", ".join(additionalUsers) + else: + add = "" + xbmcgui.Dialog().notification("Emby server", "Welcome %s%s!" % (user.currUser, add), icon="special://home/addons/plugin.video.emby/icon.png", time=2000, sound=False) # Start the Websocket Client if (self.newWebSocketThread is None):