77from xml .etree import ElementTree
88
99import requests
10- from plexapi import (BASE_HEADERS , CONFIG , TIMEOUT , X_PLEX_ENABLE_FAST_CONNECT ,
11- X_PLEX_IDENTIFIER , log , logfilter , utils )
10+ from plexapi import (BASE_HEADERS , CONFIG , TIMEOUT , X_PLEX_CONTAINER_SIZE ,
11+ X_PLEX_ENABLE_FAST_CONNECT , X_PLEX_IDENTIFIER , log , logfilter , utils )
1212from plexapi .base import PlexObject
1313from plexapi .client import PlexClient
1414from plexapi .exceptions import BadRequest , NotFound , Unauthorized
@@ -761,7 +761,7 @@ def tidal(self):
761761 data = self .query (f'{ self .MUSIC } /hubs' )
762762 return self .findItems (data )
763763
764- def watchlist (self , filter = None , sort = None , libtype = None , ** kwargs ):
764+ def watchlist (self , filter = None , sort = None , libtype = None , maxresults = 9999999 , ** kwargs ):
765765 """ Returns a list of :class:`~plexapi.video.Movie` and :class:`~plexapi.video.Show` items in the user's watchlist.
766766 Note: The objects returned are from Plex's online metadata. To get the matching item on a Plex server,
767767 search for the media using the guid.
@@ -773,6 +773,7 @@ def watchlist(self, filter=None, sort=None, libtype=None, **kwargs):
773773 ``titleSort`` (Title), ``originallyAvailableAt`` (Release Date), or ``rating`` (Critic Rating).
774774 ``dir`` can be ``asc`` or ``desc``.
775775 libtype (str, optional): 'movie' or 'show' to only return movies or shows, otherwise return all items.
776+ maxresults (int, optional): Only return the specified number of results.
776777 **kwargs (dict): Additional custom filters to apply to the search results.
777778
778779
@@ -800,9 +801,18 @@ def watchlist(self, filter=None, sort=None, libtype=None, **kwargs):
800801 if libtype :
801802 params ['type' ] = utils .searchType (libtype )
802803
804+ params ['X-Plex-Container-Start' ] = 0
805+ params ['X-Plex-Container-Size' ] = min (X_PLEX_CONTAINER_SIZE , maxresults )
803806 params .update (kwargs )
804- data = self .query (f'{ self .METADATA } /library/sections/watchlist/{ filter } ' , params = params )
805- return self ._toOnlineMetadata (self .findItems (data ))
807+
808+ results , subresults = [], '_init'
809+ while subresults and maxresults > len (results ):
810+ data = self .query (f'{ self .METADATA } /library/sections/watchlist/{ filter } ' , params = params )
811+ subresults = self .findItems (data )
812+ results += subresults [:maxresults - len (results )]
813+ params ['X-Plex-Container-Start' ] += params ['X-Plex-Container-Size' ]
814+
815+ return self ._toOnlineMetadata (results )
806816
807817 def onWatchlist (self , item ):
808818 """ Returns True if the item is on the user's watchlist.
0 commit comments