mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 14:14:19 +00:00
Add helper function to get the plural tag
This commit is contained in:
parent
cfc5bdae26
commit
1b378d3f1c
2 changed files with 11 additions and 2 deletions
|
@ -5,7 +5,7 @@ from urllib.parse import quote_plus, urlencode
|
|||
|
||||
from plexapi import log, utils
|
||||
from plexapi.exceptions import BadRequest, NotFound, UnknownType, Unsupported
|
||||
from plexapi.utils import tag_helper
|
||||
from plexapi.utils import get_plural_attr, tag_helper
|
||||
|
||||
DONT_RELOAD_FOR_KEYS = ['key', 'session']
|
||||
OPERATORS = {
|
||||
|
@ -462,7 +462,7 @@ class PlexPartialObject(PlexObject):
|
|||
"""
|
||||
if not isinstance(items, list):
|
||||
items = [items]
|
||||
value = getattr(self, tag + 's')
|
||||
value = getattr(self, get_plural_attr(tag))
|
||||
existing_cols = [t.tag for t in value if t and remove is False]
|
||||
d = tag_helper(tag, existing_cols + items, locked, remove)
|
||||
self.edit(**d)
|
||||
|
|
|
@ -335,6 +335,15 @@ def download(url, token, filename=None, savepath=None, session=None, chunksize=4
|
|||
return fullpath
|
||||
|
||||
|
||||
def get_plural_attr(tag):
|
||||
if tag == 'country':
|
||||
return 'countries'
|
||||
elif tag == 'similar':
|
||||
return 'similar'
|
||||
else:
|
||||
return tag + 's'
|
||||
|
||||
|
||||
def tag_helper(tag, items, locked=True, remove=False):
|
||||
""" Simple tag helper for editing a object. """
|
||||
if not isinstance(items, list):
|
||||
|
|
Loading…
Reference in a new issue