integrations: Add support for MovieFileDelete Radarr hook.

This commit is contained in:
Alex Vandiver 2023-05-11 18:16:53 +00:00 committed by Tim Abbott
parent 79c1123700
commit 1d5bccf4c3
3 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,23 @@
{
"movie": {
"id": 779,
"title": "Marley & Me",
"releaseDate": "2009-03-25",
"folderPath": "/home36/adbtech/media/Movies/Marley & Me (2008)",
"tmdbId": 14306,
"imdbId": "tt0822832"
},
"movieFile": {
"id": 36664,
"relativePath": "<filename>",
"path": "<fullPath>",
"quality": "Bluray-1080p",
"qualityVersion": 1,
"releaseGroup": "<rlsGroup>",
"sceneName": "The.Movie.Title.2012.1080p.BluRay.x265-<rlsGroup>",
"indexerFlags": "0",
"size": 42
},
"deleteReason": "missingFromDisk",
"eventType": "MovieFileDelete"
}

View File

@ -79,3 +79,11 @@ class RadarrHookTests(WebhookTestCase):
"The movie Batman v Superman: Dawn of Justice was deleted; its files were also deleted."
)
self.check_webhook("radarr_movie_deleted", expected_topic, expected_message)
def test_radarr_movie_file_deleted(self) -> None:
"""
Tests if radarr movie file deleted payload is handled correctly
"""
expected_topic = "Marley & Me"
expected_message = "A file with quality Bluray-1080p for the movie Marley & Me was deleted, because it is missing from disk."
self.check_webhook("radarr_movie_file_deleted", expected_topic, expected_message)

View File

@ -4,7 +4,7 @@ from zerver.decorator import webhook_view
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.validator import WildValue, check_bool, check_string, to_wild_value
from zerver.lib.validator import WildValue, check_bool, check_string, check_string_in, to_wild_value
from zerver.lib.webhooks.common import check_send_webhook_message, get_setup_webhook_message
from zerver.models import UserProfile
@ -26,6 +26,9 @@ RADARR_MESSAGE_TEMPLATE_MOVIE_GRABBED = "The movie {movie_title} has been grabbe
RADARR_MESSAGE_TEMPLATE_MOVIE_DELETED = (
"The movie {movie_title} was deleted; its files were {deleted_files} deleted."
)
RADARR_MESSAGE_TEMPLATE_MOVIE_FILE_DELETED = (
"A file with quality {quality} for the movie {movie_title} was deleted, {reason}."
)
ALL_EVENT_TYPES = [
"ApplicationUpdate",
@ -35,6 +38,7 @@ ALL_EVENT_TYPES = [
"Health",
"Grab",
"MovieDelete",
"MovieFileDelete",
]
@ -116,6 +120,21 @@ def get_body_for_movie_deleted_event(payload: WildValue) -> str:
)
def get_body_for_movie_file_deleted_event(payload: WildValue) -> str:
reasons = {
"missingFromDisk": "because it is missing from disk",
"manual": "manually",
"upgrade": "because an upgraded version exists",
"noLinkedEpisodes": "because it has no linked episodes",
"manualOverride": "via manual override",
}
return RADARR_MESSAGE_TEMPLATE_MOVIE_FILE_DELETED.format(
movie_title=payload["movie"]["title"].tame(check_string),
quality=payload["movieFile"]["quality"].tame(check_string),
reason=reasons[payload["deleteReason"].tame(check_string_in(reasons.keys()))],
)
def get_body_for_http_request(payload: WildValue) -> str:
event_type = payload["eventType"].tame(check_string)
if event_type == "Test":
@ -135,5 +154,7 @@ def get_body_for_http_request(payload: WildValue) -> str:
return get_body_for_movie_grabbed_event(payload)
elif event_type == "MovieDelete":
return get_body_for_movie_deleted_event(payload)
elif event_type == "MovieFileDelete":
return get_body_for_movie_file_deleted_event(payload)
else:
raise UnsupportedWebhookEventTypeError(event_type)