Skip to content

Commit

Permalink
Merge pull request #54 from rfsbraz/48-delete-after-played
Browse files Browse the repository at this point in the history
feat: Add watch_status support
  • Loading branch information
rfsbraz authored Dec 3, 2023
2 parents a5a3e10 + dbcd040 commit 8c201fa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ def validate_libraries(self):
f"Invalid action_mode '{library['action_mode']}' in library '{library['name']}', it should be either 'delete'."
)

if 'watch_status' in library and library['watch_status'] not in ['watched', 'unwatched']:
self.log_and_exit(
self.log_and_exit(
f"Invalid watch_status '{library.get('watch_status')}' in library "
f"'{library.get('name')}', it must be either 'watched', 'unwatched', "
"or not set."
)
)

if 'watch_status' in library and 'apply_last_watch_threshold_to_collections' in library:
self.log_and_exit(
self.log_and_exit(
f"'apply_last_watch_threshold_to_collections' cannot be used when "
f"'watch_status' is set in library '{library.get('name')}'. This would "
f"mean entire collections would be deleted when a single item in the "
f"collection meets the watch_status criteria."
)
)

if sort_config := library.get('sort', {}):
sort_field = sort_config.get('field')
sort_order = sort_config.get('order')
Expand Down
8 changes: 7 additions & 1 deletion app/deleterr.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def process_library_rules(
last_watched = (datetime.now() - watched_data["last_watched"]).days
if (
plex_media_item.collections
and last_watched_threshold
and last_watched_threshold is not None
and last_watched < last_watched_threshold
):
logger.debug(
Expand Down Expand Up @@ -456,6 +456,12 @@ def is_movie_actionable(
f"{media_data['title']} watched {last_watched} days ago, skipping"
)
return False
if library.get("watch_status") == "unwatched":
logger.debug(f"{media_data['title']} watched, skipping")
return False
elif library.get("watch_status") == "watched":
logger.debug(f"{media_data['title']} not watched, skipping")
return False

if apply_last_watch_threshold_to_collections:
if already_watched := self.watched_collections.intersection(
Expand Down
1 change: 1 addition & 0 deletions config/settings.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ libraries:
radarr: "Radarr" # The Radarr instance to use for this library
action_mode: "delete" # Actions can be "delete"
last_watched_threshold: 30 # Time threshold in days. Media not watched in this period will be subject to actions
watch_status: watched # Watched status of the media
apply_last_watch_threshold_to_collections: true # If true, the last watched threshold will be applied to all other items in the collection
added_at_threshold: 90 # Media not added in this period will be subject to actions
max_actions_per_run: 10 # Maximum number of actions to perform per run
Expand Down
1 change: 1 addition & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ For each of your Plex libraries, specify how you want Deleterr to behave. Define
| `series_type` | Only used if `sonarr` is set. It's required to filter for the show type, defaults to `standard`. | `"standard", "anime"` | `standard`, `anime`, `daily` |
| `action_mode` | The action to perform on the media items. | `delete` | `delete` |
| `last_watched_threshold` | Time threshold in days. Media watched in this period will not be actionable | `90` | - |
| `watch_status` | Watch status. Media not in this is state will not be actionable | `-` | `wathced`, `unwatched` |
| `apply_last_watch_threshold_to_collections` | If set to `true`, the last watched threshold will be applied to all other items in the same collection. | `true` | `true` / `false` |
| `added_at_threshold` | Media that added to Plex within this period (in days) will not be actionable | `180` | - |
| `max_actions_per_run` | Limit the number of actions performed per run. Defaults to `10` | `3000` | - |
Expand Down

0 comments on commit 8c201fa

Please sign in to comment.