@@ -505,7 +505,7 @@ def listChoices(self, category, libtype=None, **kwargs):
505505 key = '/library/sections/%s/%s%s' % (self .key , category , utils .joinArgs (args ))
506506 return self .fetchItems (key , cls = FilterChoice )
507507
508- def search (self , title = None , sort = None , maxresults = 999999 , libtype = None , ** kwargs ):
508+ def search (self , title = None , sort = None , maxresults = 999999 , libtype = None , container_size = None , ** kwargs ):
509509 """ Search the library. If there are many results, they will be fetched from the server
510510 in batches of X_PLEX_CONTAINER_SIZE amounts. If you're only looking for the first <num>
511511 results, it would be wise to set the maxresults option to that amount so this functions
@@ -550,15 +550,20 @@ def search(self, title=None, sort=None, maxresults=999999, libtype=None, **kwarg
550550 if libtype is not None :
551551 args ['type' ] = utils .searchType (libtype )
552552 # iterate over the results
553- results , subresults = [], '_init'
553+ results = []
554+ subresults = []
554555 args ['X-Plex-Container-Start' ] = 0
555- args ['X-Plex-Container-Size' ] = min ( X_PLEX_CONTAINER_SIZE , maxresults )
556- while subresults and maxresults > len ( results ) :
556+ args ['X-Plex-Container-Size' ] = container_size or X_PLEX_CONTAINER_SIZE
557+ while True :
557558 key = '/library/sections/%s/all%s' % (self .key , utils .joinArgs (args ))
558559 subresults = self .fetchItems (key )
559- results += subresults [:maxresults - len (results )]
560+ if not len (subresults ):
561+ break
562+ else :
563+ results .extend (subresults )
564+
560565 args ['X-Plex-Container-Start' ] += args ['X-Plex-Container-Size' ]
561- return results
566+ return results [: maxresults ]
562567
563568 def _cleanSearchFilter (self , category , value , libtype = None ):
564569 # check a few things before we begin
0 commit comments