From b2ecd2b7f914d959a862b1b63e5307e9156eedbc Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Sat, 29 May 2021 18:48:31 -0700 Subject: [PATCH] Add AdvancedSettingsMixin to Collection --- plexapi/collection.py | 20 ++++---------------- plexapi/mixins.py | 10 ++++++---- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/plexapi/collection.py b/plexapi/collection.py index 9fbdc169..0f15ad70 100644 --- a/plexapi/collection.py +++ b/plexapi/collection.py @@ -5,15 +5,14 @@ from plexapi import media, utils from plexapi.base import PlexPartialObject from plexapi.exceptions import BadRequest, NotFound, Unsupported from plexapi.library import LibrarySection -from plexapi.mixins import ArtMixin, PosterMixin +from plexapi.mixins import AdvancedSettingsMixin, ArtMixin, PosterMixin from plexapi.mixins import LabelMixin from plexapi.playqueue import PlayQueue -from plexapi.settings import Setting from plexapi.utils import deprecated @utils.registerPlexObject -class Collection(PlexPartialObject, ArtMixin, PosterMixin, LabelMixin): +class Collection(PlexPartialObject, AdvancedSettingsMixin, ArtMixin, PosterMixin, LabelMixin): """ Represents a single Collection. Attributes: @@ -172,15 +171,6 @@ class Collection(PlexPartialObject, ArtMixin, PosterMixin, LabelMixin): """ Alias to :func:`~plexapi.library.Collection.item`. """ return self.item(title) - def _preferences(self): - """ Returns a list of :class:`~plexapi.settings.Preferences` objects. """ - items = [] - data = self._server.query(self._details_key) - for item in data.iter('Setting'): - items.append(Setting(data=item, server=self._server)) - - return items - def modeUpdate(self, mode=None): """ Update the collection mode advanced setting. @@ -204,8 +194,7 @@ class Collection(PlexPartialObject, ArtMixin, PosterMixin, LabelMixin): key = mode_dict.get(mode) if key is None: raise BadRequest('Unknown collection mode : %s. Options %s' % (mode, list(mode_dict))) - part = '/library/metadata/%s/prefs?collectionMode=%s' % (self.ratingKey, key) - return self._server.query(part, method=self._server._session.put) + self.editAdvanced(collectionMode=key) def sortUpdate(self, sort=None): """ Update the collection order advanced setting. @@ -228,8 +217,7 @@ class Collection(PlexPartialObject, ArtMixin, PosterMixin, LabelMixin): key = sort_dict.get(sort) if key is None: raise BadRequest('Unknown sort dir: %s. Options: %s' % (sort, list(sort_dict))) - part = '/library/metadata/%s/prefs?collectionSort=%s' % (self.ratingKey, key) - return self._server.query(part, method=self._server._session.put) + self.editAdvanced(collectionSort=key) def addItems(self, items): """ Add items to the collection. diff --git a/plexapi/mixins.py b/plexapi/mixins.py index 05d1f40f..49d8332a 100644 --- a/plexapi/mixins.py +++ b/plexapi/mixins.py @@ -39,16 +39,18 @@ class AdvancedSettingsMixin(object): """ Edit a Plex object's advanced settings. """ data = {} key = '%s/prefs?' % self.key - preferences = {pref.id: list(pref.enumValues.keys()) for pref in self.preferences()} + preferences = {pref.id: pref for pref in self.preferences() if pref.enumValues} for settingID, value in kwargs.items(): try: - enums = preferences[settingID] + pref = preferences[settingID] except KeyError: raise NotFound('%s not found in %s' % (value, list(preferences.keys()))) - if value in enums: + + enumValues = pref.enumValues + if enumValues.get(value, enumValues.get(str(value))): data[settingID] = value else: - raise NotFound('%s not found in %s' % (value, enums)) + raise NotFound('%s not found in %s' % (value, list(enumValues))) url = key + urlencode(data) self._server.query(url, method=self._server._session.put)