mirror of https://github.com/zulip/zulip.git
integrations: Add support for MovieFileDelete Radarr hook.
This commit is contained in:
parent
79c1123700
commit
1d5bccf4c3
|
@ -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"
|
||||||
|
}
|
|
@ -79,3 +79,11 @@ class RadarrHookTests(WebhookTestCase):
|
||||||
"The movie Batman v Superman: Dawn of Justice was deleted; its files were also deleted."
|
"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)
|
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)
|
||||||
|
|
|
@ -4,7 +4,7 @@ from zerver.decorator import webhook_view
|
||||||
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
|
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
|
||||||
from zerver.lib.request import REQ, has_request_variables
|
from zerver.lib.request import REQ, has_request_variables
|
||||||
from zerver.lib.response import json_success
|
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.lib.webhooks.common import check_send_webhook_message, get_setup_webhook_message
|
||||||
from zerver.models import UserProfile
|
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 = (
|
RADARR_MESSAGE_TEMPLATE_MOVIE_DELETED = (
|
||||||
"The movie {movie_title} was deleted; its files were {deleted_files} 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 = [
|
ALL_EVENT_TYPES = [
|
||||||
"ApplicationUpdate",
|
"ApplicationUpdate",
|
||||||
|
@ -35,6 +38,7 @@ ALL_EVENT_TYPES = [
|
||||||
"Health",
|
"Health",
|
||||||
"Grab",
|
"Grab",
|
||||||
"MovieDelete",
|
"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:
|
def get_body_for_http_request(payload: WildValue) -> str:
|
||||||
event_type = payload["eventType"].tame(check_string)
|
event_type = payload["eventType"].tame(check_string)
|
||||||
if event_type == "Test":
|
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)
|
return get_body_for_movie_grabbed_event(payload)
|
||||||
elif event_type == "MovieDelete":
|
elif event_type == "MovieDelete":
|
||||||
return get_body_for_movie_deleted_event(payload)
|
return get_body_for_movie_deleted_event(payload)
|
||||||
|
elif event_type == "MovieFileDelete":
|
||||||
|
return get_body_for_movie_file_deleted_event(payload)
|
||||||
else:
|
else:
|
||||||
raise UnsupportedWebhookEventTypeError(event_type)
|
raise UnsupportedWebhookEventTypeError(event_type)
|
||||||
|
|
Loading…
Reference in New Issue