Skip to content

Commit

Permalink
feat(radarr): Add support to exclude movies on deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
rfsbraz committed Apr 8, 2024
1 parent f7acea6 commit 005fd1b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
28 changes: 27 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import yaml

from app import logger
from app.constants import VALID_ACTION_MODES, VALID_SORT_FIELDS, VALID_SORT_ORDERS
from app.constants import (
SETTINGS_PER_ACTION,
SETTINGS_PER_INSTANCE,
VALID_ACTION_MODES,
VALID_SORT_FIELDS,
VALID_SORT_ORDERS,
)
from app.modules.tautulli import Tautulli
from app.modules.trakt import Trakt
from app.utils import validate_units
Expand Down Expand Up @@ -72,6 +78,17 @@ def validate_trakt(self):
logger.debug(f"Error: {err}")
return False

def validate_settings_for_instance(self, library):
instance_type = "radarr" if "radarr" in library else "sonarr"
for setting in library:
if (
setting in SETTINGS_PER_INSTANCE
and instance_type in SETTINGS_PER_INSTANCE[setting]
):
self.log_and_exit(
f"'{setting}' can only be set for {instance_type} instances"
)

def validate_sonarr_and_radarr(self):
sonarr_settings = self.settings.get("sonarr", [])
radarr_settings = self.settings.get("radarr", [])
Expand Down Expand Up @@ -183,6 +200,15 @@ def validate_action_mode(self, library):
f"Invalid action_mode '{library['action_mode']}' in library '{library['name']}', it should be either 'delete'."
)

# Validate settings per action
for setting in library:
if setting in SETTINGS_PER_ACTION and library[
"action_mode"
] not in SETTINGS_PER_ACTION.get(setting, []):
self.log_and_exit(
f"'{setting}' can only be set when action_mode is '{library['action_mode']}' for library '{library['name']}'."
)

def validate_watch_status(self, library):
if "watch_status" in library and library["watch_status"] not in [
"watched",
Expand Down
8 changes: 8 additions & 0 deletions app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@

# Valid action modes
VALID_ACTION_MODES = ["delete"]

SETTINGS_PER_ACTION = {
"exclude_on_delete": ["delete"],
}

SETTINGS_PER_INSTANCE = {
"exclude_on_delete": ["radarr"],
}
12 changes: 10 additions & 2 deletions app/media_cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,17 @@ def delete_movie_if_allowed(
library.get("name"),
)
if input().lower() == "y":
radarr_instance.del_movie(radarr_movie["id"], delete_files=True)
radarr_instance.del_movie(
radarr_movie["id"],
delete_files=True,
add_exclusion=library.get("exclude_on_delete", False),
)
else:
radarr_instance.del_movie(radarr_movie["id"], delete_files=True)
radarr_instance.del_movie(
radarr_movie["id"],
delete_files=True,
add_exclusion=library.get("exclude_on_delete", False),
)

def get_library_config(self, config, show):
return next(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_media_cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def test_delete_movie_if_allowed_interactive_yes(mock_input, standard_config):
# Assert
mock_input.assert_called_once()
radarr_instance.del_movie.assert_called_once_with(
radarr_movie["id"], delete_files=True
radarr_movie["id"], delete_files=True, add_exclusion=False
)


Expand Down Expand Up @@ -1120,7 +1120,7 @@ def test_delete_movie_if_allowed_not_interactive(standard_config):

# Assert
radarr_instance.del_movie.assert_called_once_with(
radarr_movie["id"], delete_files=True
radarr_movie["id"], delete_files=True, add_exclusion=False
)


Expand Down

0 comments on commit 005fd1b

Please sign in to comment.