updated tag edits

pull/309/head
meisnate12 3 years ago
parent e3f6a8fa24
commit 585f5b7591

@ -698,29 +698,24 @@ class Plex:
updated = False updated = False
key = builder.filter_translation[attr] if attr in builder.filter_translation else attr key = builder.filter_translation[attr] if attr in builder.filter_translation else attr
if add_tags or remove_tags or sync_tags: if add_tags or remove_tags or sync_tags:
_add_tags = [f"{t[:1].upper()}{t[1:]}" for t in add_tags] if add_tags else None _add_tags = add_tags if add_tags else []
_remove_tags = [f"{t[:1].upper()}{t[1:]}" for t in remove_tags] if remove_tags else None _remove = [t.lower() for t in remove_tags] if remove_tags else []
_sync_tags = [t.lower() for t in sync_tags] if sync_tags else None _sync_tags = sync_tags if sync_tags else []
item_tags = [item_tag.tag for item_tag in getattr(obj, key)] _sync = [t.lower() for t in _sync_tags]
input_tags = [] item_tags = [item_tag.tag.lower() for item_tag in getattr(obj, key)]
if _add_tags: _add = _add_tags + _sync_tags
input_tags.extend(_add_tags) if _add:
if _sync_tags: add = [f"{t[:1].upper()}{t[1:]}" for t in _add if t.lower() not in item_tags]
input_tags.extend(_sync_tags) if add:
if _sync_tags or _remove_tags:
remove_method = getattr(obj, f"remove{attr.capitalize()}")
for tag in item_tags:
if (_sync_tags and tag.lower() not in _sync_tags) or (_remove_tags and tag in _remove_tags):
updated = True updated = True
self.query_data(remove_method, tag) self.query_data(getattr(obj, f"add{attr.capitalize()}"), add)
logger.info(f"Detail: {attr.capitalize()} {tag} removed") logger.info(f"Detail: {attr.capitalize()} {add} added")
if input_tags: if _remove or _sync:
add_method = getattr(obj, f"add{attr.capitalize()}") remove = [t for t in item_tags if t not in _sync or t in _remove]
for tag in input_tags: if remove:
if tag not in item_tags:
updated = True updated = True
self.query_data(add_method, tag) self.query_data(getattr(obj, f"remove{attr.capitalize()}"), remove)
logger.info(f"Detail: {attr.capitalize()} {tag} added") logger.info(f"Detail: {attr.capitalize()} {remove} removed")
return updated return updated
def update_item_from_assets(self, item): def update_item_from_assets(self, item):

Loading…
Cancel
Save