[30] add batch collection adds

This commit is contained in:
meisnate12 2023-11-13 16:19:59 -05:00
parent 924dc527eb
commit d1ae53a588
4 changed files with 10 additions and 34 deletions

View file

@ -1 +1 @@
1.19.1-develop29
1.19.1-develop30

View file

@ -2526,8 +2526,6 @@ class CollectionBuilder:
amount_unchanged += 1
else:
items_added.append(item)
if not self.playlist: # Delete TODO: BATCH COLLECTIONS
self.library.alter_collection(item, name, smart_label_collection=self.smart_label_collection) # Delete TODO: BATCH COLLECTIONS
amount_added += 1
if self.details["changes_webhooks"]:
self.notification_additions.append(util.item_set(item, self.library.get_id_from_maps(item.ratingKey)))
@ -2537,8 +2535,8 @@ class CollectionBuilder:
logger.info(f"Playlist: {self.name} created")
elif self.playlist and items_added:
self.obj.addItems(items_added)
#elif items_added: # Uncomment TODO: BATCH COLLECTIONS
# self.library.alter_collection(items_added, name, smart_label_collection=self.smart_label_collection) # Uncomment TODO: BATCH COLLECTIONS
elif items_added:
self.library.alter_collection(items_added, name, smart_label_collection=self.smart_label_collection)
if self.do_report and items_added:
self.library.add_additions(self.name, [(i.title, self.library.get_id_from_maps(i.ratingKey)) for i in items_added], self.library.is_movie)
logger.exorcise()
@ -2561,16 +2559,14 @@ class CollectionBuilder:
number_text = f"{i}/{total}"
logger.info(f"{number_text:>{spacing}} | {self.name} {self.Type} | - | {util.item_title(item)}")
items_removed.append(item)
if not self.playlist: # Delete TODO: BATCH COLLECTIONS
self.library.alter_collection(item, self.name, smart_label_collection=self.smart_label_collection, add=False) # Delete TODO: BATCH COLLECTIONS
amount_removed += 1
if self.details["changes_webhooks"]:
self.notification_removals.append(util.item_set(item, self.library.get_id_from_maps(item.ratingKey)))
if self.playlist and items_removed:
self.library._reload(self.obj)
self.obj.removeItems(items_removed)
#elif items_removed: # Uncomment TODO: BATCH COLLECTIONS
# self.library.alter_collection(items_removed, self.name, smart_label_collection=self.smart_label_collection, add=False) # Uncomment TODO: BATCH COLLECTIONS
elif items_removed:
self.library.alter_collection(items_removed, self.name, smart_label_collection=self.smart_label_collection, add=False)
if self.do_report and items_removed:
self.library.add_removed(self.name, [(i.title, self.library.get_id_from_maps(i.ratingKey)) for i in items_removed], self.library.is_movie)
logger.info("")

View file

@ -880,30 +880,10 @@ class Plex(Library):
r._data.attrib.get('promotedToOwnHome'), r._data.attrib.get('promotedToSharedHome'))
for r in self.Plex.fetchItems(f"/hubs/sections/{self.Plex.key}/manage")]
def alter_collection(self, item, collection, smart_label_collection=False, add=True):
if smart_label_collection:
self.query_data(item.addLabel if add else item.removeLabel, collection)
else:
locked = True
item = self.reload(item)
if self.agent in ["tv.plex.agents.movie", "tv.plex.agents.series"]:
field = next((f for f in item.fields if f.name == "collection"), None)
locked = field is not None
try:
self.query_collection(item, collection, locked=locked, add=add)
except TypeError:
logger.info(item.collections)
for col in item.collections:
logger.info(col.id)
logger.info(col.key)
logger.info(col.tag)
raise
# Change item to items and delete all the above #TODO: BATCH COLLECTIONS
#self.Plex.batchMultiEdits(items)
#self.query_data(getattr(self.Plex, f"{'add' if add else 'remove'}{'Label' if smart_label_collection else 'Collection'}"), collection)
#self.Plex.saveMultiEdits()
def alter_collection(self, items, collection, smart_label_collection=False, add=True):
self.Plex.batchMultiEdits(items)
self.query_data(getattr(self.Plex, f"{'add' if add else 'remove'}{'Label' if smart_label_collection else 'Collection'}"), collection)
self.Plex.saveMultiEdits()
def move_item(self, collection, item, after=None):
key = f"{collection.key}/items/{item}/move"

View file

@ -4,7 +4,7 @@ lxml==4.9.3
num2words==0.5.13
pathvalidate==3.2.0
pillow==10.1.0
PlexAPI==4.15.5
PlexAPI==4.15.6
psutil==5.9.6
python-dotenv==1.0.0
requests==2.31.0