@@ -169,7 +169,7 @@ def add(self, name='', type='', agent='', scanner='', location='', language='en'
169169 name (str): Name of the library
170170 agent (str): Example com.plexapp.agents.imdb
171171 type (str): movie, show, # check me
172- location (str): /path/to/files
172+ location (str or list ): /path/to/files, ["/path/to/files", "/path/to/morefiles"]
173173 language (str): Two letter language fx en
174174 kwargs (dict): Advanced options should be passed as a dict. where the id is the key.
175175
@@ -308,8 +308,16 @@ def add(self, name='', type='', agent='', scanner='', location='', language='en'
308308 40:South Africa, 41:Spain, 42:Sweden, 43:Switzerland, 44:Taiwan, 45:Trinidad,
309309 46:United Kingdom, 47:United States, 48:Uruguay, 49:Venezuela.
310310 """
311- part = '/library/sections?name=%s&type=%s&agent=%s&scanner=%s&language=%s&location=%s' % (
312- quote_plus (name ), type , agent , quote_plus (scanner ), language , quote_plus (location )) # noqa E126
311+ if isinstance (location , str ):
312+ location = [location ]
313+ locations = []
314+ for path in location :
315+ if not self ._server .isBrowsable (path ):
316+ raise BadRequest ('Path: %s does not exist.' % path )
317+ locations .append (('location' , path ))
318+
319+ part = '/library/sections?name=%s&type=%s&agent=%s&scanner=%s&language=%s&%s' % (
320+ quote_plus (name ), type , agent , quote_plus (scanner ), language , urlencode (locations , doseq = True )) # noqa E126
313321 if kwargs :
314322 part += urlencode (kwargs )
315323 return self ._server .query (part , method = self ._server ._session .post )
@@ -486,16 +494,76 @@ def reload(self):
486494 return self
487495
488496 def edit (self , agent = None , ** kwargs ):
489- """ Edit a library (Note: agent is required) . See :class:`~plexapi.library.Library` for example usage.
497+ """ Edit a library. See :class:`~plexapi.library.Library` for example usage.
490498
491499 Parameters:
500+ agent (str, optional): The library agent.
492501 kwargs (dict): Dict of settings to edit.
493502 """
494503 if not agent :
495504 agent = self .agent
496- part = '/library/sections/%s?agent=%s&%s' % (self .key , agent , urlencode (kwargs ))
505+
506+ locations = []
507+ if kwargs .get ('location' ):
508+ if isinstance (kwargs ['location' ], str ):
509+ kwargs ['location' ] = [kwargs ['location' ]]
510+ for path in kwargs .pop ('location' ):
511+ if not self ._server .isBrowsable (path ):
512+ raise BadRequest ('Path: %s does not exist.' % path )
513+ locations .append (('location' , path ))
514+
515+ params = list (kwargs .items ()) + locations
516+
517+ part = '/library/sections/%s?agent=%s&%s' % (self .key , agent , urlencode (params , doseq = True ))
497518 self ._server .query (part , method = self ._server ._session .put )
498519
520+ def addLocations (self , location ):
521+ """ Add a location to a library.
522+
523+ Parameters:
524+ location (str or list): A single folder path, list of paths.
525+
526+ Example:
527+
528+ .. code-block:: python
529+
530+ LibrarySection.addLocations('/path/1')
531+ LibrarySection.addLocations(['/path/1', 'path/2', '/path/3'])
532+ """
533+ locations = self .locations
534+ if isinstance (location , str ):
535+ location = [location ]
536+ for path in location :
537+ if not self ._server .isBrowsable (path ):
538+ raise BadRequest ('Path: %s does not exist.' % path )
539+ locations .append (path )
540+ self .edit (location = locations )
541+
542+ def removeLocations (self , location ):
543+ """ Remove a location from a library.
544+
545+ Parameters:
546+ location (str or list): A single folder path, list of paths.
547+
548+ Example:
549+
550+ .. code-block:: python
551+
552+ LibrarySection.removeLocations('/path/1')
553+ LibrarySection.removeLocations(['/path/1', 'path/2', '/path/3'])
554+ """
555+ locations = self .locations
556+ if isinstance (location , str ):
557+ location = [location ]
558+ for path in location :
559+ if path in locations :
560+ locations .remove (path )
561+ else :
562+ raise BadRequest ('Path: %s does not exist in the library.' % location )
563+ if len (locations ) == 0 :
564+ raise BadRequest ('You are unable to remove all locations from a library.' )
565+ self .edit (location = locations )
566+
499567 def get (self , title ):
500568 """ Returns the media item with the specified title.
501569
0 commit comments