Don't show delet context menu if now allowed by PMS
This commit is contained in:
parent
f595455776
commit
9869131464
7 changed files with 46 additions and 5 deletions
|
@ -543,3 +543,16 @@ def delete_item_from_pms(plexid):
|
||||||
else:
|
else:
|
||||||
log.error('Could not delete Plex id %s from the PMS' % plexid)
|
log.error('Could not delete Plex id %s from the PMS' % plexid)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_PMS_settings(url, token):
|
||||||
|
"""
|
||||||
|
Retrieve the PMS' settings via <url>/:/
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import xbmcaddon
|
||||||
import PlexAPI
|
import PlexAPI
|
||||||
from PlexFunctions import GetPlexMetadata, delete_item_from_pms
|
from PlexFunctions import GetPlexMetadata, delete_item_from_pms
|
||||||
import embydb_functions as embydb
|
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
|
from dialogs import context
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -110,7 +110,8 @@ class ContextMenu(object):
|
||||||
# Refresh item
|
# Refresh item
|
||||||
options.append(OPTIONS['Refresh'])
|
options.append(OPTIONS['Refresh'])
|
||||||
# Delete item, only if the Plex Home main user is logged in
|
# 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'])
|
options.append(OPTIONS['Delete'])
|
||||||
# Addon settings
|
# Addon settings
|
||||||
options.append(OPTIONS['Addon'])
|
options.append(OPTIONS['Addon'])
|
||||||
|
|
|
@ -1290,7 +1290,7 @@ def watchlater():
|
||||||
if window('plex_token') == '':
|
if window('plex_token') == '':
|
||||||
log.error('No watch later - not signed in to plex.tv')
|
log.error('No watch later - not signed in to plex.tv')
|
||||||
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
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')
|
log.error('No watch later - restricted user')
|
||||||
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
return xbmcplugin.endOfDirectory(int(sys.argv[1]), False)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import downloadutils
|
||||||
import userclient
|
import userclient
|
||||||
|
|
||||||
import PlexAPI
|
import PlexAPI
|
||||||
from PlexFunctions import GetMachineIdentifier
|
from PlexFunctions import GetMachineIdentifier, get_PMS_settings
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -42,6 +42,8 @@ class InitialSetup():
|
||||||
self.plexLogin = plexdict['plexLogin']
|
self.plexLogin = plexdict['plexLogin']
|
||||||
self.plexToken = plexdict['plexToken']
|
self.plexToken = plexdict['plexToken']
|
||||||
self.plexid = plexdict['plexid']
|
self.plexid = plexdict['plexid']
|
||||||
|
# Token for the PMS, not plex.tv
|
||||||
|
self.pms_token = settings('accessToken')
|
||||||
if self.plexToken:
|
if self.plexToken:
|
||||||
log.debug('Found a plex.tv token in the settings')
|
log.debug('Found a plex.tv token in the settings')
|
||||||
|
|
||||||
|
@ -197,8 +199,28 @@ class InitialSetup():
|
||||||
server = self._UserPickPMS()
|
server = self._UserPickPMS()
|
||||||
else:
|
else:
|
||||||
server = self._AutoPickPMS()
|
server = self._AutoPickPMS()
|
||||||
|
if server is not None:
|
||||||
|
self._write_PMS_settings(server['baseURL'], server['accesstoken'])
|
||||||
return server
|
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):
|
def _AutoPickPMS(self):
|
||||||
"""
|
"""
|
||||||
Will try to pick PMS based on machineIdentifier saved in file settings
|
Will try to pick PMS based on machineIdentifier saved in file settings
|
||||||
|
@ -401,6 +423,7 @@ class InitialSetup():
|
||||||
if getNewIP is False:
|
if getNewIP is False:
|
||||||
log.info("Using PMS %s with machineIdentifier %s"
|
log.info("Using PMS %s with machineIdentifier %s"
|
||||||
% (self.server, self.serverid))
|
% (self.server, self.serverid))
|
||||||
|
self._write_PMS_settings(self.server, self.pms_token)
|
||||||
return
|
return
|
||||||
|
|
||||||
# If not already retrieved myplex info, optionally let user sign in
|
# If not already retrieved myplex info, optionally let user sign in
|
||||||
|
|
|
@ -170,6 +170,7 @@ class UserClient(threading.Thread):
|
||||||
# This is the token for plex.tv for the current user
|
# This is the token for plex.tv for the current user
|
||||||
# Is only '' if user is not signed in to plex.tv
|
# Is only '' if user is not signed in to plex.tv
|
||||||
window('plex_token', value=settings('plexToken'))
|
window('plex_token', value=settings('plexToken'))
|
||||||
|
window('plex_restricteduser', value=settings('plex_restricteduser'))
|
||||||
window('pms_server', value=self.currServer)
|
window('pms_server', value=self.currServer)
|
||||||
window('plex_machineIdentifier', value=self.machineIdentifier)
|
window('plex_machineIdentifier', value=self.machineIdentifier)
|
||||||
window('plex_servername', value=self.servername)
|
window('plex_servername', value=self.servername)
|
||||||
|
@ -298,6 +299,7 @@ class UserClient(threading.Thread):
|
||||||
window('plex_servername', clear=True)
|
window('plex_servername', clear=True)
|
||||||
window('currUserId', clear=True)
|
window('currUserId', clear=True)
|
||||||
window('plex_username', clear=True)
|
window('plex_username', clear=True)
|
||||||
|
window('plex_restricteduser', clear=True)
|
||||||
|
|
||||||
settings('username', value='')
|
settings('username', value='')
|
||||||
settings('userid', value='')
|
settings('userid', value='')
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
<setting id="companionPort" label="39005" type="number" default="3005" option="int" visible="eq(-3,true)" subsetting="true" />
|
<setting id="companionPort" label="39005" type="number" default="3005" option="int" visible="eq(-3,true)" subsetting="true" />
|
||||||
|
|
||||||
<setting id="plex_restricteduser" type="bool" default="false" visible="false"/>
|
<setting id="plex_restricteduser" type="bool" default="false" visible="false"/>
|
||||||
|
<setting id="plex_allows_mediaDeletion" type="bool" default="true" visible="false"/>
|
||||||
</category>
|
</category>
|
||||||
|
|
||||||
<category label="30506"><!-- Sync Options -->
|
<category label="30506"><!-- Sync Options -->
|
||||||
|
|
|
@ -102,7 +102,8 @@ class Service():
|
||||||
"pms_server", "plex_machineIdentifier", "plex_servername",
|
"pms_server", "plex_machineIdentifier", "plex_servername",
|
||||||
"plex_authenticated", "PlexUserImage", "useDirectPaths",
|
"plex_authenticated", "PlexUserImage", "useDirectPaths",
|
||||||
"suspend_LibraryThread", "plex_terminateNow",
|
"suspend_LibraryThread", "plex_terminateNow",
|
||||||
"kodiplextimeoffset", "countError", "countUnauthorized"
|
"kodiplextimeoffset", "countError", "countUnauthorized",
|
||||||
|
"plex_restricteduser", "plex_allows_mediaDeletion"
|
||||||
]
|
]
|
||||||
for prop in properties:
|
for prop in properties:
|
||||||
window(prop, clear=True)
|
window(prop, clear=True)
|
||||||
|
|
Loading…
Add table
Reference in a new issue