mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-24 20:53:09 +00:00
Add methods to lock and unlock a field for all items in a library (#861)
* Add plex folder to .gitignore * Add method to lock/unlock a field for all items in a library * Add test to lock/unlock all posters in a library
This commit is contained in:
parent
8ffbe85190
commit
fcbea70549
3 changed files with 44 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -29,4 +29,5 @@ MANIFEST
|
|||
venv/
|
||||
|
||||
# path for the test lib.
|
||||
plex/
|
||||
tools/plex
|
|
@ -674,6 +674,36 @@ class LibrarySection(PlexObject):
|
|||
|
||||
self.edit(**data)
|
||||
|
||||
def _lockUnlockAllField(self, field, libtype=None, locked=True):
|
||||
""" Lock or unlock a field for all items in the library. """
|
||||
libtype = libtype or self.TYPE
|
||||
args = {
|
||||
'type': utils.searchType(libtype),
|
||||
'%s.locked' % field: int(locked)
|
||||
}
|
||||
key = '/library/sections/%s/all%s' % (self.key, utils.joinArgs(args))
|
||||
self._server.query(key, method=self._server._session.put)
|
||||
|
||||
def lockAllField(self, field, libtype=None):
|
||||
""" Lock a field for all items in the library.
|
||||
|
||||
Parameters:
|
||||
field (str): The field to lock (e.g. thumb, rating, collection).
|
||||
libtype (str, optional): The library type to lock (movie, show, season, episode,
|
||||
artist, album, track, photoalbum, photo). Default is the main library type.
|
||||
"""
|
||||
self._lockUnlockAllField(field, libtype=libtype, locked=True)
|
||||
|
||||
def unlockAllField(self, field, libtype=None):
|
||||
""" Unlock a field for all items in the library.
|
||||
|
||||
Parameters:
|
||||
field (str): The field to unlock (e.g. thumb, rating, collection).
|
||||
libtype (str, optional): The library type to lock (movie, show, season, episode,
|
||||
artist, album, track, photoalbum, photo). Default is the main library type.
|
||||
"""
|
||||
self._lockUnlockAllField(field, libtype=libtype, locked=False)
|
||||
|
||||
def timeline(self):
|
||||
""" Returns a timeline query for this library section. """
|
||||
key = '/library/sections/%s/timeline' % self.key
|
||||
|
|
|
@ -424,6 +424,19 @@ def test_library_editAdvanced_default(movies):
|
|||
assert str(setting.value) == str(setting.default)
|
||||
|
||||
|
||||
def test_library_lockUnlockAllFields(movies):
|
||||
for movie in movies.all():
|
||||
assert 'thumb' not in [f.name for f in movie.fields]
|
||||
|
||||
movies.lockAllField('thumb')
|
||||
for movie in movies.all():
|
||||
assert 'thumb' in [f.name for f in movie.fields]
|
||||
|
||||
movies.unlockAllField('thumb')
|
||||
for movie in movies.all():
|
||||
assert 'thumb' not in [f.name for f in movie.fields]
|
||||
|
||||
|
||||
def test_search_with_weird_a(plex, tvshows):
|
||||
ep_title = "Coup de Grâce"
|
||||
result_root = plex.search(ep_title)
|
||||
|
|
Loading…
Reference in a new issue