@@ -184,17 +184,22 @@ def item(self, title):
184184 @cached_data_property
185185 def _items (self ):
186186 """ Cache for items. """
187+ return self ._fetchItems ()
188+
189+ def _fetchItems (self , libtype = None ):
190+ """ Returns a list of all items in the playlist, optionally filtered by library type. """
187191 if self .radio :
188192 return []
189193
190- key = self ._buildQueryKey (f'{ self .key } /items' )
194+ params = {'type' : utils .searchType (libtype )} if libtype else {}
195+ key = self ._buildQueryKey (f'{ self .key } /items' , ** params )
191196 items = self .fetchItems (key )
192197
193198 # Cache server connections to avoid reconnecting for each item
194199 _servers = {}
195200 for item in items :
196- if item . sourceURI :
197- serverID = item . sourceURI .split ('/' )[2 ]
201+ if sourceURI := getattr ( item , ' sourceURI' , None ) :
202+ serverID = sourceURI .split ('/' )[2 ]
198203 if serverID not in _servers :
199204 try :
200205 _servers [serverID ] = self ._server .myPlexAccount ().resource (serverID ).connect ()
@@ -205,8 +210,16 @@ def _items(self):
205210
206211 return items
207212
208- def items (self ):
209- """ Returns a list of all items in the playlist. """
213+ def items (self , libtype = None ):
214+ """ Returns a list of all items in the playlist.
215+
216+ Parameters:
217+ libtype (str): Optional filter to return items grouped by a specific library type
218+ (movie, show, season, episode, artist, album, track, photoalbum, photo).
219+ (e.g. shows in a playlist, or albums in a playlist)
220+ """
221+ if libtype :
222+ return self ._fetchItems (libtype = libtype )
210223 return self ._items
211224
212225 def get (self , title ):
0 commit comments