@@ -150,40 +150,47 @@ def cleanBundles(self):
150150 """
151151 # TODO: Should this check the response for success or the correct mediaprefix?
152152 self ._server .query ('/library/clean/bundles?async=1' , method = self ._server ._session .put )
153+ return self
153154
154155 def emptyTrash (self ):
155156 """ If a library has items in the Library Trash, use this option to empty the Trash. """
156157 for section in self .sections ():
157158 section .emptyTrash ()
159+ return self
158160
159161 def optimize (self ):
160162 """ The Optimize option cleans up the server database from unused or fragmented data.
161163 For example, if you have deleted or added an entire library or many items in a
162164 library, you may like to optimize the database.
163165 """
164166 self ._server .query ('/library/optimize?async=1' , method = self ._server ._session .put )
167+ return self
165168
166169 def update (self ):
167170 """ Scan this library for new items."""
168171 self ._server .query ('/library/sections/all/refresh' )
172+ return self
169173
170174 def cancelUpdate (self ):
171175 """ Cancel a library update. """
172176 key = '/library/sections/all/refresh'
173177 self ._server .query (key , method = self ._server ._session .delete )
178+ return self
174179
175180 def refresh (self ):
176181 """ Forces a download of fresh media information from the internet.
177182 This can take a long time. Any locked fields are not modified.
178183 """
179184 self ._server .query ('/library/sections/all/refresh?force=1' )
185+ return self
180186
181187 def deleteMediaPreviews (self ):
182188 """ Delete the preview thumbnails for the all sections. This cannot be
183189 undone. Recreating media preview files can take hours or even days.
184190 """
185191 for section in self .sections ():
186192 section .deleteMediaPreviews ()
193+ return self
187194
188195 def add (self , name = '' , type = '' , agent = '' , scanner = '' , location = '' , language = 'en' , * args , ** kwargs ):
189196 """ Simplified add for the most common options.
@@ -549,6 +556,7 @@ def edit(self, agent=None, **kwargs):
549556
550557 part = '/library/sections/%s?agent=%s&%s' % (self .key , agent , urlencode (params , doseq = True ))
551558 self ._server .query (part , method = self ._server ._session .put )
559+ return self
552560
553561 def addLocations (self , location ):
554562 """ Add a location to a library.
@@ -570,7 +578,7 @@ def addLocations(self, location):
570578 if not self ._server .isBrowsable (path ):
571579 raise BadRequest ('Path: %s does not exist.' % path )
572580 locations .append (path )
573- self .edit (location = locations )
581+ return self .edit (location = locations )
574582
575583 def removeLocations (self , location ):
576584 """ Remove a location from a library.
@@ -595,7 +603,7 @@ def removeLocations(self, location):
595603 raise BadRequest ('Path: %s does not exist in the library.' % location )
596604 if len (locations ) == 0 :
597605 raise BadRequest ('You are unable to remove all locations from a library.' )
598- self .edit (location = locations )
606+ return self .edit (location = locations )
599607
600608 def get (self , title ):
601609 """ Returns the media item with the specified title.
@@ -718,7 +726,7 @@ def editAdvanced(self, **kwargs):
718726 else :
719727 raise NotFound ('%s not found in %s' % (value , enums ))
720728
721- self .edit (** data )
729+ return self .edit (** data )
722730
723731 def defaultAdvanced (self ):
724732 """ Edit all of library's advanced settings to default. """
@@ -730,7 +738,7 @@ def defaultAdvanced(self):
730738 else :
731739 data [key % setting .id ] = setting .default
732740
733- self .edit (** data )
741+ return self .edit (** data )
734742
735743 def _lockUnlockAllField (self , field , libtype = None , locked = True ):
736744 """ Lock or unlock a field for all items in the library. """
@@ -741,6 +749,7 @@ def _lockUnlockAllField(self, field, libtype=None, locked=True):
741749 }
742750 key = '/library/sections/%s/all%s' % (self .key , utils .joinArgs (args ))
743751 self ._server .query (key , method = self ._server ._session .put )
752+ return self
744753
745754 def lockAllField (self , field , libtype = None ):
746755 """ Lock a field for all items in the library.
@@ -750,7 +759,7 @@ def lockAllField(self, field, libtype=None):
750759 libtype (str, optional): The library type to lock (movie, show, season, episode,
751760 artist, album, track, photoalbum, photo). Default is the main library type.
752761 """
753- self ._lockUnlockAllField (field , libtype = libtype , locked = True )
762+ return self ._lockUnlockAllField (field , libtype = libtype , locked = True )
754763
755764 def unlockAllField (self , field , libtype = None ):
756765 """ Unlock a field for all items in the library.
@@ -760,7 +769,7 @@ def unlockAllField(self, field, libtype=None):
760769 libtype (str, optional): The library type to lock (movie, show, season, episode,
761770 artist, album, track, photoalbum, photo). Default is the main library type.
762771 """
763- self ._lockUnlockAllField (field , libtype = libtype , locked = False )
772+ return self ._lockUnlockAllField (field , libtype = libtype , locked = False )
764773
765774 def timeline (self ):
766775 """ Returns a timeline query for this library section. """
@@ -794,11 +803,13 @@ def analyze(self):
794803 """
795804 key = '/library/sections/%s/analyze' % self .key
796805 self ._server .query (key , method = self ._server ._session .put )
806+ return self
797807
798808 def emptyTrash (self ):
799809 """ If a section has items in the Trash, use this option to empty the Trash. """
800810 key = '/library/sections/%s/emptyTrash' % self .key
801811 self ._server .query (key , method = self ._server ._session .put )
812+ return self
802813
803814 def update (self , path = None ):
804815 """ Scan this section for new media.
@@ -810,25 +821,29 @@ def update(self, path=None):
810821 if path is not None :
811822 key += '?path=%s' % quote_plus (path )
812823 self ._server .query (key )
824+ return self
813825
814826 def cancelUpdate (self ):
815827 """ Cancel update of this Library Section. """
816828 key = '/library/sections/%s/refresh' % self .key
817829 self ._server .query (key , method = self ._server ._session .delete )
830+ return self
818831
819832 def refresh (self ):
820833 """ Forces a download of fresh media information from the internet.
821834 This can take a long time. Any locked fields are not modified.
822835 """
823836 key = '/library/sections/%s/refresh?force=1' % self .key
824837 self ._server .query (key )
838+ return self
825839
826840 def deleteMediaPreviews (self ):
827841 """ Delete the preview thumbnails for items in this library. This cannot
828842 be undone. Recreating media preview files can take hours or even days.
829843 """
830844 key = '/library/sections/%s/indexes' % self .key
831845 self ._server .query (key , method = self ._server ._session .delete )
846+ return self
832847
833848 def _loadFilters (self ):
834849 """ Retrieves and caches the list of :class:`~plexapi.library.FilteringType` and
0 commit comments