Add method to get a collection or playlist by title in a library

This commit is contained in:
JonnyWong16 2021-05-27 22:17:29 -07:00
parent 0512e9f38e
commit 2cd29f435a
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -1371,9 +1371,15 @@ class LibrarySection(PlexObject):
title, section=self, items=items, smart=smart, limit=limit,
libtype=libtype, sort=sort, filters=filters, **kwargs)
@deprecated('use "collections" (plural) instead')
def collection(self, **kwargs):
return self.collections()
def collection(self, title):
""" Returns the collection with the specified title.
Parameters:
title (str): Title of the item to return.
"""
results = self.collections(title__iexact=title)
if results:
return results[0]
def collections(self, **kwargs):
""" Returns a list of collections from this library section.
@ -1390,6 +1396,16 @@ class LibrarySection(PlexObject):
title, section=self, items=items, smart=smart, limit=limit,
sort=sort, filters=filters, **kwargs)
def playlist(self, title):
""" Returns the playlist with the specified title.
Parameters:
title (str): Title of the item to return.
"""
results = self.playlists(title__iexact=title)
if results:
return results[0]
def playlists(self, **kwargs):
""" Returns a list of playlists from this library section. """
key = '/playlists?type=15&playlistType=%s&sectionID=%s' % (self.CONTENT_TYPE, self.key)