Skip to content

Commit f95f792

Browse files
committed
Merge branch 'pr/366'
2 parents d6be6fa + 52833b1 commit f95f792

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

plexapi/library.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def all(self, sort=None, **kwargs):
386386
sortStr = ''
387387
if sort is not None:
388388
sortStr = '?sort=' + sort
389-
389+
390390
key = '/library/sections/%s/all%s' % (self.key, sortStr)
391391
return self.fetchItems(key, **kwargs)
392392

@@ -994,6 +994,8 @@ def _loadData(self, data):
994994
self.childCount = utils.cast(int, data.attrib.get('childCount'))
995995
self.minYear = utils.cast(int, data.attrib.get('minYear'))
996996
self.maxYear = utils.cast(int, data.attrib.get('maxYear'))
997+
self.collectionMode = data.attrib.get('collectionMode')
998+
self.collectionSort = data.attrib.get('collectionSort')
997999

9981000
@property
9991001
def children(self):
@@ -1006,5 +1008,48 @@ def delete(self):
10061008
part = '/library/metadata/%s' % self.ratingKey
10071009
return self._server.query(part, method=self._server._session.delete)
10081010

1011+
def modeUpdate(self, mode=None):
1012+
""" Update Collection Mode
1013+
1014+
Parameters:
1015+
mode: default (Library default)
1016+
hide (Hide Collection)
1017+
hideItems (Hide Items in this Collection)
1018+
showItems (Show this Collection and its Items)
1019+
Example:
1020+
1021+
collection = 'plexapi.library.Collections'
1022+
collection.updateMode(mode="hide")
1023+
"""
1024+
mode_dict = {'default': '-2',
1025+
'hide': '0',
1026+
'hideItems': '1',
1027+
'showItems': '2'}
1028+
key = mode_dict.get(mode)
1029+
if key is None:
1030+
raise BadRequest('Unknown collection mode : %s. Options %s' % (mode, list(mode_dict)))
1031+
part = '/library/metadata/%s/prefs?collectionMode=%s' % (self.ratingKey, key)
1032+
return self._server.query(part, method=self._server._session.put)
1033+
1034+
def sortUpdate(self, sort=None):
1035+
""" Update Collection Sorting
1036+
1037+
Parameters:
1038+
sort: realease (Order Collection by realease dates)
1039+
alpha (Order Collection Alphabetically)
1040+
1041+
Example:
1042+
1043+
colleciton = 'plexapi.library.Collections'
1044+
collection.updateSort(mode="alpha")
1045+
"""
1046+
sort_dict = {'release': '0',
1047+
'alpha': '1'}
1048+
key = sort_dict.get(sort)
1049+
if key is None:
1050+
raise BadRequest('Unknown sort dir: %s. Options: %s' % (sort, list(sort_dict)))
1051+
part = '/library/metadata/%s/prefs?collectionSort=%s' % (self.ratingKey, key)
1052+
return self._server.query(part, method=self._server._session.put)
1053+
10091054
# def edit(self, **kwargs):
10101055
# TODO

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ def movie(movies):
187187
return movies.get('Elephants Dream')
188188

189189

190+
@pytest.fixture()
191+
def collection(plex):
192+
return plex.library.section('Movies').collection()[0]
193+
194+
190195
@pytest.fixture()
191196
def artist(music):
192197
return music.get('Infinite State')

tests/test_library.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,41 @@ def test_library_and_section_search_for_movie(plex):
201201
assert l_search == s_search
202202

203203

204+
def test_library_Colletion_modeUpdate_hide(collection):
205+
collection.modeUpdate(mode='hide')
206+
collection.reload()
207+
assert collection.collectionMode == '0'
208+
209+
210+
def test_library_Colletion_modeUpdate_default(collection):
211+
collection.modeUpdate(mode='default')
212+
collection.reload()
213+
assert collection.collectionMode == '-2'
214+
215+
216+
def test_library_Colletion_modeUpdate_hideItems(collection):
217+
collection.modeUpdate(mode='hideItems')
218+
collection.reload()
219+
assert collection.collectionMode == '1'
220+
221+
222+
def test_library_Colletion_modeUpdate_showItems(collection):
223+
collection.modeUpdate(mode='showItems')
224+
collection.reload()
225+
assert collection.collectionMode == '2'
226+
227+
228+
def test_library_Colletion_sortAlpha(collection):
229+
collection.sortUpdate(sort='alpha')
230+
collection.reload()
231+
assert collection.collectionSort == '1'
232+
233+
234+
def test_library_Colletion_sortRelease(collection):
235+
collection.sortUpdate(sort='release')
236+
collection.reload()
237+
assert collection.collectionSort == '0'
238+
204239
# This started failing on more recent Plex Server builds
205240
@pytest.mark.xfail
206241
def test_search_with_apostrophe(plex):

0 commit comments

Comments
 (0)