77from plexapi .base import Playable , PlexPartialObject
88from plexapi .exceptions import BadRequest , NotFound , Unsupported
99from plexapi .library import LibrarySection , MusicSection
10- from plexapi .mixins import SmartFilterMixin , ArtMixin , PosterMixin
10+ from plexapi .mixins import SmartFilterMixin , ArtMixin , PosterMixin , PlaylistEditMixins
1111from plexapi .utils import deprecated
1212
1313
1414@utils .registerPlexObject
1515class Playlist (
1616 PlexPartialObject , Playable ,
1717 SmartFilterMixin ,
18- ArtMixin , PosterMixin
18+ ArtMixin , PosterMixin ,
19+ PlaylistEditMixins
1920):
2021 """ Represents a single Playlist.
2122
@@ -42,6 +43,7 @@ class Playlist(
4243 smart (bool): True if the playlist is a smart playlist.
4344 summary (str): Summary of the playlist.
4445 title (str): Name of the playlist.
46+ titleSort (str): Title to use when sorting (defaults to title).
4547 type (str): 'playlist'
4648 updatedAt (datetime): Datetime the playlist was updated.
4749 """
@@ -71,6 +73,7 @@ def _loadData(self, data):
7173 self .smart = utils .cast (bool , data .attrib .get ('smart' ))
7274 self .summary = data .attrib .get ('summary' )
7375 self .title = data .attrib .get ('title' )
76+ self .titleSort = data .attrib .get ('titleSort' , self .title )
7477 self .type = data .attrib .get ('type' )
7578 self .updatedAt = utils .toDatetime (data .attrib .get ('updatedAt' ))
7679 self ._items = None # cache for self.items
@@ -224,7 +227,7 @@ def addItems(self, items):
224227 self ._server .query (key , method = self ._server ._session .put )
225228 return self
226229
227- @deprecated ('use "removeItems" instead' , stacklevel = 3 )
230+ @deprecated ('use "removeItems" instead' )
228231 def removeItem (self , item ):
229232 self .removeItems (item )
230233
@@ -308,10 +311,15 @@ def updateFilters(self, limit=None, sort=None, filters=None, **kwargs):
308311
309312 def _edit (self , ** kwargs ):
310313 """ Actually edit the playlist. """
314+ if isinstance (self ._edits , dict ):
315+ self ._edits .update (kwargs )
316+ return self
317+
311318 key = f'{ self .key } { utils .joinArgs (kwargs )} '
312319 self ._server .query (key , method = self ._server ._session .put )
313320 return self
314321
322+ @deprecated ('use "editTitle" and "editSummary" instead' )
315323 def edit (self , title = None , summary = None ):
316324 """ Edit the playlist.
317325
@@ -384,7 +392,7 @@ def _createFromM3U(cls, server, title, section, m3ufilepath):
384392 key = f"/playlists/upload{ utils .joinArgs (args )} "
385393 server .query (key , method = server ._session .post )
386394 try :
387- return server .playlists (sectionId = section .key , guid__endswith = m3ufilepath )[0 ].edit ( title = title ).reload ()
395+ return server .playlists (sectionId = section .key , guid__endswith = m3ufilepath )[0 ].editTitle ( title ).reload ()
388396 except IndexError :
389397 raise BadRequest ('Failed to create playlist from m3u file.' ) from None
390398
0 commit comments