Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions plexapi/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from urllib.parse import quote, quote_plus, unquote, urlencode

from plexapi import X_PLEX_CONTAINER_SIZE, log, utils
from plexapi.base import PlexObject, PlexPartialObject
from plexapi.base import OPERATORS, PlexObject, PlexPartialObject
from plexapi.exceptions import BadRequest, NotFound
from plexapi.media import MediaTag
from plexapi.settings import Setting
Expand Down Expand Up @@ -437,18 +437,12 @@ def get(self, title):
key = '/library/sections/%s/all?title=%s' % (self.key, quote(title, safe=''))
return self.fetchItem(key, title__iexact=title)

def all(self, sort=None, **kwargs):
""" Returns a list of media from this library section.

Parameters:
sort (string): The sort string
def all(self, libtype=None, **kwargs):
""" Returns a list of all items from this library section.
See description of :func:`plexapi.library.LibrarySection.search()` for details about filtering / sorting.
"""
sortStr = ''
if sort is not None:
sortStr = '?sort=' + sort

key = '/library/sections/%s/all%s' % (self.key, sortStr)
return self.fetchItems(key, **kwargs)
libtype = libtype or self.TYPE
return self.search(libtype=libtype, **kwargs)

def folders(self):
""" Returns a list of available :class:`~plexapi.library.Folder` for this library section.
Expand Down Expand Up @@ -672,8 +666,10 @@ def search(self, title=None, sort=None, maxresults=None,
"""
# cleanup the core arguments
args = {}
for category, value in kwargs.items():
args[category] = self._cleanSearchFilter(category, value, libtype)
for category, value in list(kwargs.items()):
if category.split('__')[-1] not in OPERATORS:
args[category] = self._cleanSearchFilter(category, value, libtype)
del kwargs[category]
if title is not None:
args['title'] = title
if sort is not None:
Expand All @@ -690,7 +686,7 @@ def search(self, title=None, sort=None, maxresults=None,
while True:
key = '/library/sections/%s/all%s' % (self.key, utils.joinArgs(args))
subresults = self.fetchItems(key, container_start=container_start,
container_size=container_size)
container_size=container_size, **kwargs)
if not len(subresults):
if offset > self.totalSize:
log.info("container_start is higher then the number of items in the library")
Expand Down Expand Up @@ -1054,6 +1050,13 @@ class PhotoSection(LibrarySection):
CONTENT_TYPE = 'photo'
METADATA_TYPE = 'photo'

def all(self, libtype=None, **kwargs):
""" Returns a list of all items from this library section.
See description of :func:`plexapi.library.LibrarySection.search()` for details about filtering / sorting.
"""
libtype = libtype or 'photoalbum'
return self.search(libtype=libtype, **kwargs)

def collections(self, **kwargs):
raise NotImplementedError('Collections are not available for a Photo library.')

Expand Down
2 changes: 1 addition & 1 deletion tests/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_library_section_get_movie(plex):
def test_library_section_movies_all(movies):
# size should always be none unless pagenation is being used.
assert movies.totalSize == 4
assert len(movies.all(container_start=0, container_size=1)) == 1
assert len(movies.all(container_start=0, container_size=1, maxresults=1)) == 1


def test_library_section_delete(movies, patched_http_call):
Expand Down