[25] rework logic around collection deletion (#2147)

This commit is contained in:
Chaz Larson 2024-07-02 08:58:44 -05:00 committed by GitHub Action
parent 5047c7a408
commit 8db89bab47
4 changed files with 31 additions and 14 deletions

View file

@ -1,8 +1,9 @@
# Requirements Update (requirements will need to be reinstalled) # Requirements Update (requirements will need to be reinstalled)
Added tenacity requirement at 8.4.2 Added tenacity requirement at 8.4.2
Update pillow requirement to 10.4.0
Update PlexAPI requirement to 4.15.14 Update PlexAPI requirement to 4.15.14
Update psutil requirement to 6.0.0 Update psutil requirement to 6.0.0
Update setuptools requirement to 70.1.1 Update setuptools requirement to 70.2.0
# Removed Features # Removed Features
@ -16,6 +17,7 @@ Added [`letterboxd_user_lists`](https://kometa.wiki/en/latest/files/dynamic_type
# Bug Fixes # Bug Fixes
Fixed multiple anime `int()` Errors Fixed multiple anime `int()` Errors
Fixed #2100 `verify_ssl` wasn't working when downloading images Fixed #2100 `verify_ssl` wasn't working when downloading images
Fixed an issue with `delete_collections` where items were being deleted if they only matched one criteria vs all criteria
Fixed `imdb_watchlist` Fixed `imdb_watchlist`
Various other Minor Fixes Various other Minor Fixes

View file

@ -1 +1 @@
2.0.2-build24 2.0.2-build25

View file

@ -64,6 +64,29 @@ class Operations:
logger.debug(f"Item Operation: {self.library.items_library_operation}") logger.debug(f"Item Operation: {self.library.items_library_operation}")
logger.debug("") logger.debug("")
def should_be_deleted(col_in, labels_in, configured_in, managed_in, less_in):
if all((x is None for x in [configured_in, managed_in, less_in])):
return False
less_check = True
if less_in is not None:
less_check = col_in.childCount < less_in
logger.trace(f"{col_in.title} - collection size: {col_in.childCount} < less: {less_in}, DELETE: {less_check}")
managed_check = True
if managed_in is not None:
is_managed = "PMM" in labels_in or "Kometa" in labels_in
managed_check = managed_in == is_managed
logger.trace(f"{col_in.title} - collection managed: {is_managed} vs managed: {managed_in}, DELETE: {managed_check}")
configured_check = True
if configured_in is not None:
is_configured = col_in.title in self.library.collections
configured_check = configured_in == is_configured
logger.trace(f"{col_in.title} - collection configured: {is_configured} vs configured: {configured_in}, DELETE: {configured_check}")
return all((less_check, managed_check, configured_check))
if self.library.split_duplicates: if self.library.split_duplicates:
items = self.library.search(**{"duplicate": True}) items = self.library.search(**{"duplicate": True})
for item in items: for item in items:
@ -1055,16 +1078,8 @@ class Operations:
logger.ghost(f"Reading Collection: {i}/{len(all_collections)} {col.title}") logger.ghost(f"Reading Collection: {i}/{len(all_collections)} {col.title}")
col = self.library.reload(col, force=True) col = self.library.reload(col, force=True)
labels = [la.tag for la in self.library.item_labels(col)] labels = [la.tag for la in self.library.item_labels(col)]
if (less is not None or managed is not None or configured is not None) \
and (less is None or col.childCount < less) \ if should_be_deleted(col, labels, configured, managed, less):
and (managed is None
or (managed is True and "PMM" in labels)
or (managed is True and "Kometa" in labels)
or (managed is False and "PMM" not in labels)
or (managed is False and "Kometa" not in labels)) \
and (configured is None
or (configured is True and col.title in self.library.collections)
or (configured is False and col.title not in self.library.collections)):
try: try:
self.library.delete(col) self.library.delete(col)
logger.info(f"{col.title} Deleted") logger.info(f"{col.title} Deleted")

View file

@ -3,7 +3,7 @@ GitPython==3.1.43
lxml==5.2.2 lxml==5.2.2
num2words==0.5.13 num2words==0.5.13
pathvalidate==3.2.0 pathvalidate==3.2.0
pillow==10.3.0 pillow==10.4.0
PlexAPI==4.15.14 PlexAPI==4.15.14
psutil==6.0.0 psutil==6.0.0
python-dotenv==1.0.1 python-dotenv==1.0.1
@ -12,5 +12,5 @@ requests==2.32.3
tenacity==8.4.2 tenacity==8.4.2
ruamel.yaml==0.18.6 ruamel.yaml==0.18.6
schedule==1.2.2 schedule==1.2.2
setuptools==70.1.1 setuptools==70.2.0
tmdbapis==1.2.16 tmdbapis==1.2.16