Skip to content

Commit 981e965

Browse files
Added class/libtype for collections and library search function
1 parent 6238fa5 commit 981e965

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

plexapi/library.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,10 @@ class MovieSection(LibrarySection):
565565
TAG = 'Directory'
566566
TYPE = 'movie'
567567

568+
def collection(self, **kwargs):
569+
""" Returns a list of collections from this library section. """
570+
return self.search(libtype='collection', **kwargs)
571+
568572

569573
class ShowSection(LibrarySection):
570574
""" Represents a :class:`~plexapi.library.LibrarySection` section containing tv shows.
@@ -600,6 +604,10 @@ def recentlyAdded(self, libtype='episode', maxresults=50):
600604
"""
601605
return self.search(sort='addedAt:desc', libtype=libtype, maxresults=maxresults)
602606

607+
def collection(self, **kwargs):
608+
""" Returns a list of collections from this library section. """
609+
return self.search(libtype='collection', **kwargs)
610+
603611

604612
class MusicSection(LibrarySection):
605613
""" Represents a :class:`~plexapi.library.LibrarySection` section containing music artists.
@@ -634,6 +642,10 @@ def searchTracks(self, **kwargs):
634642
""" Search for a track. See :func:`~plexapi.library.LibrarySection.search()` for usage. """
635643
return self.search(libtype='track', **kwargs)
636644

645+
def collection(self, **kwargs):
646+
""" Returns a list of collections from this library section. """
647+
return self.search(libtype='collection', **kwargs)
648+
637649

638650
class PhotoSection(LibrarySection):
639651
""" Represents a :class:`~plexapi.library.LibrarySection` section containing photos.
@@ -714,3 +726,25 @@ def _loadData(self, data):
714726

715727
def __len__(self):
716728
return self.size
729+
730+
@utils.registerPlexObject
731+
class Collections(PlexObject):
732+
733+
TAG = 'Directory'
734+
TYPE = 'collection'
735+
736+
def _loadData(self, data):
737+
self.ratingKey = data.attrib.get('ratingKey')
738+
self.key = data.attrib.get('key')
739+
self.type = data.attrib.get('type')
740+
self.title = data.attrib.get('title')
741+
self.subtype = data.attrib.get('subtype')
742+
self.summary = data.attrib.get('summary')
743+
self.index = data.attrib.get('index')
744+
self.thumb = data.attrib.get('thumb')
745+
self.addedAt = data.attrib.get('addedAt')
746+
self.updatedAt = data.attrib.get('updatedAt')
747+
self.childCount = data.attrib.get('childCount')
748+
self.maxYear = data.attrib.get('maxYear')
749+
self.children = self.fetchItems(self.key)
750+

plexapi/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# Search Types - Plex uses these to filter specific media types when searching.
1616
# Library Types - Populated at runtime
1717
SEARCHTYPES = {'movie': 1, 'show': 2, 'season': 3, 'episode': 4,
18-
'artist': 8, 'album': 9, 'track': 10, 'photo': 14}
18+
'artist': 8, 'album': 9, 'track': 10, 'photo': 14,
19+
'collection': 18}
1920
PLEXOBJECTS = {}
2021

2122

@@ -129,8 +130,8 @@ def searchType(libtype):
129130
""" Returns the integer value of the library string type.
130131
131132
Parameters:
132-
libtype (str): LibType to lookup (movie, show, season, episode, artist, album, track)
133-
133+
libtype (str): LibType to lookup (movie, show, season, episode, artist, album, track,
134+
collection)
134135
Raises:
135136
NotFound: Unknown libtype
136137
"""

0 commit comments

Comments
 (0)