Always build default details key

This commit is contained in:
JonnyWong16 2020-11-21 12:08:27 -08:00
parent 0d27aa3f8e
commit d59d199ee7
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
3 changed files with 12 additions and 12 deletions

View file

@ -44,9 +44,9 @@ class PlexObject(object):
self._server = server
self._data = data
self._initpath = initpath or self.key
self._details_key = ''
if data is not None:
self._loadData(data)
self._details_key = self._buildDetailsKey()
def __repr__(self):
uid = self._clean(self.firstAttr('_baseurl', 'key', 'id', 'playQueueID', 'uri'))
@ -89,22 +89,21 @@ class PlexObject(object):
except UnknownType:
return None
def _buildDetailsKey(self, buildOnly=False, **kwargs):
def _buildDetailsKey(self, **kwargs):
""" Builds the details key with the XML include parameters.
All parameters are included by default with the option to override each parameter
or disable each parameter individually by setting it to False or 0.
"""
details_key = self.key
if hasattr(self, '_includes'):
includes = {}
for k, v in self._includes.items():
value = kwargs.get(k, v)
if value not in [False, 0, '0']:
includes[k] = 1 if value is True else value
details_key = self.key + '?' + urlencode(includes, doseq=True)
if buildOnly:
return details_key
self._details_key = details_key
return self._details_key
if includes:
details_key += '?' + urlencode(includes, doseq=True)
return details_key
def fetchItem(self, ekey, cls=None, **kwargs):
""" Load the specified key to find and build the first item with the
@ -227,7 +226,8 @@ class PlexObject(object):
key (string, optional): The key to reload.
**kwargs (dict): A dictionary of XML include parameters.
"""
key = key or self._buildDetailsKey(**kwargs) or self.key
details_key = self._buildDetailsKey(**kwargs) if kwargs else self._details_key
key = key or details_key or self.key
if not key:
raise Unsupported('Cannot reload an object not built from a URL.')
self._initpath = key

View file

@ -1470,7 +1470,7 @@ class Collections(PlexPartialObject):
def _preferences(self):
""" Returns a list of :class:`~plexapi.settings.Preferences` objects. """
items = []
data = self._server.query(self._buildDetailsKey(buildOnly=True))
data = self._server.query(self._details_key)
for item in data.iter('Setting'):
items.append(Setting(data=item, server=self._server))

View file

@ -461,7 +461,7 @@ class Show(Video):
def preferences(self):
""" Returns a list of :class:`~plexapi.settings.Preferences` objects. """
items = []
data = self._server.query(self._buildDetailsKey(buildOnly=True))
data = self._server.query(self._details_key)
for item in data.iter('Preferences'):
for elem in item:
setting = settings.Preferences(data=elem, server=self._server)
@ -495,7 +495,7 @@ class Show(Video):
def hubs(self):
""" Returns a list of :class:`~plexapi.library.Hub` objects. """
data = self._server.query(self._buildDetailsKey(buildOnly=True))
data = self._server.query(self._details_key)
for item in data.iter('Related'):
return self.findItems(item, library.Hub)
@ -503,7 +503,7 @@ class Show(Video):
""" Returns shows On Deck :class:`~plexapi.video.Video` object.
If show is unwatched, return will likely be the first episode.
"""
data = self._server.query(self._buildDetailsKey(buildOnly=True))
data = self._server.query(self._details_key)
return self.findItems([item for item in data.iter('OnDeck')][0])[0]
def seasons(self, **kwargs):