diff --git a/resources/lib/PlexFunctions.py b/resources/lib/PlexFunctions.py index aa41031b..132e8b63 100644 --- a/resources/lib/PlexFunctions.py +++ b/resources/lib/PlexFunctions.py @@ -543,3 +543,16 @@ def delete_item_from_pms(plexid): else: log.error('Could not delete Plex id %s from the PMS' % plexid) return False + + +def get_PMS_settings(url, token): + """ + Retrieve the PMS' settings via /:/ + + Call with url: scheme://ip:port + """ + return downloadutils.DownloadUtils().downloadUrl( + '%s/:/prefs' % url, + authenticate=False, + verifySSL=False, + headerOptions={'X-Plex-Token': token} if token else None) diff --git a/resources/lib/context_entry.py b/resources/lib/context_entry.py index ea3333ca..65564aff 100644 --- a/resources/lib/context_entry.py +++ b/resources/lib/context_entry.py @@ -10,7 +10,7 @@ import xbmcaddon import PlexAPI from PlexFunctions import GetPlexMetadata, delete_item_from_pms import embydb_functions as embydb -from utils import settings, dialog, language as lang, kodiSQL +from utils import window, settings, dialog, language as lang, kodiSQL from dialogs import context ############################################################################### @@ -110,7 +110,8 @@ class ContextMenu(object): # Refresh item options.append(OPTIONS['Refresh']) # Delete item, only if the Plex Home main user is logged in - if settings('plex_restricteduser') != 'true': + if (window('plex_restricteduser') != 'true' and + window('plex_allows_mediaDeletion') == 'true'): options.append(OPTIONS['Delete']) # Addon settings options.append(OPTIONS['Addon']) diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index a66744db..bf97270f 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -1290,7 +1290,7 @@ def watchlater(): if window('plex_token') == '': log.error('No watch later - not signed in to plex.tv') return xbmcplugin.endOfDirectory(int(sys.argv[1]), False) - if settings('plex_restricteduser') == 'true': + if window('plex_restricteduser') == 'true': log.error('No watch later - restricted user') return xbmcplugin.endOfDirectory(int(sys.argv[1]), False) diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 62ea9e20..4527c38a 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -12,7 +12,7 @@ import downloadutils import userclient import PlexAPI -from PlexFunctions import GetMachineIdentifier +from PlexFunctions import GetMachineIdentifier, get_PMS_settings ############################################################################### @@ -42,6 +42,8 @@ class InitialSetup(): self.plexLogin = plexdict['plexLogin'] self.plexToken = plexdict['plexToken'] self.plexid = plexdict['plexid'] + # Token for the PMS, not plex.tv + self.pms_token = settings('accessToken') if self.plexToken: log.debug('Found a plex.tv token in the settings') @@ -197,8 +199,28 @@ class InitialSetup(): server = self._UserPickPMS() else: server = self._AutoPickPMS() + if server is not None: + self._write_PMS_settings(server['baseURL'], server['accesstoken']) return server + def _write_PMS_settings(self, url, token): + """ + Sets certain settings for server by asking for the PMS' settings + Call with url: scheme://ip:port + """ + xml = get_PMS_settings(url, token) + try: + xml.attrib + except AttributeError: + log.error('Could not get PMS settings for %s' % url) + return + for entry in xml: + if entry.attrib.get('id', '') == 'allowMediaDeletion': + settings('plex_allows_mediaDeletion', + value=entry.attrib.get('value', 'true')) + window('plex_allows_mediaDeletion', + value=entry.attrib.get('value', 'true')) + def _AutoPickPMS(self): """ Will try to pick PMS based on machineIdentifier saved in file settings @@ -401,6 +423,7 @@ class InitialSetup(): if getNewIP is False: log.info("Using PMS %s with machineIdentifier %s" % (self.server, self.serverid)) + self._write_PMS_settings(self.server, self.pms_token) return # If not already retrieved myplex info, optionally let user sign in diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index 78aff86b..a7a9fa75 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -170,6 +170,7 @@ class UserClient(threading.Thread): # This is the token for plex.tv for the current user # Is only '' if user is not signed in to plex.tv window('plex_token', value=settings('plexToken')) + window('plex_restricteduser', value=settings('plex_restricteduser')) window('pms_server', value=self.currServer) window('plex_machineIdentifier', value=self.machineIdentifier) window('plex_servername', value=self.servername) @@ -298,6 +299,7 @@ class UserClient(threading.Thread): window('plex_servername', clear=True) window('currUserId', clear=True) window('plex_username', clear=True) + window('plex_restricteduser', clear=True) settings('username', value='') settings('userid', value='') diff --git a/resources/settings.xml b/resources/settings.xml index 2fcc6dc7..f96c3182 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -40,6 +40,7 @@ + diff --git a/service.py b/service.py index 799b91cd..16dd13ed 100644 --- a/service.py +++ b/service.py @@ -102,7 +102,8 @@ class Service(): "pms_server", "plex_machineIdentifier", "plex_servername", "plex_authenticated", "PlexUserImage", "useDirectPaths", "suspend_LibraryThread", "plex_terminateNow", - "kodiplextimeoffset", "countError", "countUnauthorized" + "kodiplextimeoffset", "countError", "countUnauthorized", + "plex_restricteduser", "plex_allows_mediaDeletion" ] for prop in properties: window(prop, clear=True)