Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't do the less check on smart collections #2275

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Fixes an issue where Prime Video overlays/collections would not be built when th
Fixed the `cast` search option for the `imdb_search` builder
Fixes #2258 `imdb_list` sort was not being parsed correctly
Fixes `letterboxd_list` rating filter to use a 1-10 rating vs 1-100 to reflect how letterboxd ratings work on their website
Fixes #2274 Enhance handling of smart collections in deletion
Fixed the `ids_to_anidb` lookup for anime movies and shows
2 changes: 2 additions & 0 deletions docs/config/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ You can create individual blocks of operations by using a list under `operations
<tr><td>`configured: true`</td><td>Collection must be Configured to be deleted<br>(collection is in the config file of the specific Kometa run)</td></tr>
<tr><td>`configured: false`</td><td>Collection must be Unconfigured to be deleted<br>(collection is not in the config file of the specific Kometa run)</td></tr>
<tr><td>`less: ###`</td><td>Collection must contain less than the given number of items to be deleted.<br>### is a Number greater than 0<br>Optional value which if undefined means collections will be deleted regardless of how many items they have</td></tr>
<tr><td>`ignore_empty_smart_collections: false`</td><td>Do not apply less check to empty smart collections<br>This allows retaining things like smart collections that show movies without subtitles or the like.</td></tr>

</table>

**The collection does not need to be scheduled to be considered configured and only needs to be in the config file.**
Expand Down
3 changes: 2 additions & 1 deletion json-schema/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,8 @@
"properties": {
"configured": { "type": "boolean" },
"managed": { "type": "boolean" },
"less": { "type": "integer" }
"less": { "type": "integer" },
"ignore_empty_smart_collections": { "type": "boolean" }
},
"required": []
},
Expand Down
30 changes: 16 additions & 14 deletions json-schema/kitchen_sink_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ libraries:
delete_collections:
configured: false # False - Collection must be an Unconfigured Collection to be deleted (collection is not in the config file of the specific Kometa run).
managed: false # False - Collection must be an Unmanaged Collection to be deleted (the collection does not have the Kometa label)
less: 99999 # Effectively all collections regardless of teh number of items in the collection
less: 99999 # Effectively all collections regardless of the number of items in the collection
ignore_empty_smart_collections: true # Don't do the less check on empty smart collections
mass_user_rating_update: mdb_tomatoes # Update user ratings with mdb_tomatoes
mass_critic_rating_update: imdb # Update critic ratings with imdb
mass_audience_rating_update: tmdb # Update audience ratings with tmdb
Expand Down Expand Up @@ -758,7 +759,8 @@ libraries:
delete_collections:
configured: false # False - Collection must be an Unconfigured Collection to be deleted (collection is not in the config file of the specific Kometa run).
managed: false # False - Collection must be an Unmanaged Collection to be deleted (the collection does not have the Kometa label)
less: 99999 # Effectively all collections regardless of teh number of items in the collection
less: 99999 # Effectively all collections regardless of the number of items in the collection
ignore_empty_smart_collections: true # Don't do the less check on empty smart collections
mass_user_rating_update: mdb_tomatoes # Update user ratings with mdb_tomatoes
mass_critic_rating_update: imdb # Update critic ratings with imdb
mass_audience_rating_update: tmdb # Update audience ratings with tmdb
Expand Down Expand Up @@ -859,8 +861,8 @@ webhooks: # Can be individually specif
version: (redacted)
delete: (redacted)
plex: # Can be individually specified per library as well; REQUIRED for the script to run
url: (redacted)
token: (redacted)
url: http://10.10.10.10:1234
token: THIS_IS_A_FAKE_TOKEN
timeout: 60
clean_bundles: true
empty_trash: true
Expand All @@ -873,19 +875,19 @@ tmdb: # REQUIRED for the script to
region: CA # Upper case ISO 3166-1 Code
cache_expiration: 60
tautulli: # Can be individually specified per library as well
url: (redacted)
apikey: (redacted)
url: http://10.10.10.10:1234
apikey: THIS_IS_A_FAKE_TOKEN
omdb:
apikey: (redacted)
apikey: THIS_IS_A_FAKE_TOKEN
cache_expiration: 60
mdblist:
apikey: (redacted)
apikey: THIS_IS_A_FAKE_TOKEN
cache_expiration: 60
notifiarr:
apikey: (redacted)
apikey: THIS_IS_A_FAKE_TOKEN
radarr: # Can be individually specified per library as well
url: (redacted)
token: (redacted)
url: http://10.10.10.10:1234
token: THIS_IS_A_FAKE_TOKEN
root_folder_path: /data/media/movies
monitor: true
availability: announced
Expand All @@ -900,8 +902,8 @@ radarr: # Can be individually specified
ignore_cache: false
monitor_existing: false
sonarr: # Can be individually specified per library as well
url: (redacted)
token: (redacted)
url: http://10.10.10.10:1234
token: THIS_IS_A_FAKE_TOKEN
root_folder_path: /data/media/tv
monitor: all
quality_profile: Any
Expand All @@ -920,7 +922,7 @@ sonarr: # Can be individually specified
monitor_existing: false
anidb:
client: (redacted)
version: (redacted)
version: 1234
language: en
cache_expiration: 60
username: (redacted)
Expand Down
1 change: 1 addition & 0 deletions json-schema/prototype_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ libraries:
managed: false
configured: true
less: 123
ignore_empty_smart_collections: true

Anime:
collection_files:
Expand Down
1 change: 1 addition & 0 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ def check_for_attribute(data, attribute, parent=None, test_list=None, translatio
"managed": check_for_attribute(input_dict, "managed", var_type="bool", default_is_none=True, save=False),
"configured": check_for_attribute(input_dict, "configured", var_type="bool", default_is_none=True, save=False),
"less": check_for_attribute(input_dict, "less", var_type="int", default_is_none=True, save=False, int_min=1),
"ignore_empty_smart_collections": check_for_attribute(input_dict, "ignore_empty_smart_collections", var_type="bool", default=True, save=False),
}
elif op == "mass_collection_content_rating_update":
section_final[op] = {
Expand Down
16 changes: 11 additions & 5 deletions modules/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ def run_operations(self):
logger.debug(f"Item Operation: {self.library.items_library_operation}")
logger.debug("")

def should_be_deleted(col_in, labels_in, configured_in, managed_in, less_in):
def should_be_deleted(col_in, labels_in, configured_in, managed_in, less_in, ignore_smart_in):
if all((x is None for x in [configured_in, managed_in, less_in])):
return False

less_check = True
less_check = not ignore_smart_in if col_in.smart else 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}")
if less_check:
col_count = col_in.childCount if col_in.childCount is not None else 0
less_check = col_count < less_in
logger.trace(f"{col_in.title} - collection size: {col_count} < less: {less_in}, DELETE: {less_check}")
else:
logger.trace(f"{col_in.title} - skipping size check: smart - {col_in.smart}, ignore_smart - {ignore_smart_in}")


managed_check = True
if managed_in is not None:
Expand Down Expand Up @@ -1071,6 +1076,7 @@ def get_batch_info(placement, total, display_attr, total_count, display_value=No
less = self.library.delete_collections["less"] if self.library.delete_collections and self.library.delete_collections["less"] is not None else None
managed = self.library.delete_collections["managed"] if self.library.delete_collections else None
configured = self.library.delete_collections["configured"] if self.library.delete_collections else None
ignore_smart = self.library.delete_collections["ignore_empty_smart_collections"] if self.library.delete_collections else True
unmanaged_collections = []
unconfigured_collections = []
all_collections = self.library.get_all_collections()
Expand All @@ -1079,7 +1085,7 @@ def get_batch_info(placement, total, display_attr, total_count, display_value=No
col = self.library.reload(col, force=True)
labels = [la.tag for la in self.library.item_labels(col)]

if should_be_deleted(col, labels, configured, managed, less):
if should_be_deleted(col, labels, configured, managed, less, ignore_smart):
try:
self.library.delete(col)
logger.info(f"{col.title} Deleted")
Expand Down
Loading