-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathradarr.sh
97 lines (92 loc) · 2.66 KB
/
radarr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
# load env file from $NTFY_ENV or script dir
SCRIPTPATH=${NTFY_ENV:-$(dirname "$0")/.env}
[ -f ${SCRIPTPATH} ] && . "${SCRIPTPATH}" || echo "ENV missing: ${SCRIPTPATH}"
if [[ -n $ntfy_password && -n $ntfy_token ]]; then
echo "Use ntfy_username and ntfy_password OR ntfy_token"
exit 1
elif [ -n "$ntfy_password" ]; then
ntfy_base64=$( echo -n "$ntfy_username:$ntfy_password" | base64 )
ntfy_auth="Authorization: Basic $ntfy_base64"
elif [ -n "$ntfy_token" ]; then
ntfy_auth="Authorization: Bearer $ntfy_token"
else
ntfy_auth=""
fi
ntfy_title=$radarr_movie_title
ntfy_message=" "
if [ "$radarr_eventtype" == "Test" ]; then
ntfy_tag=information_source
ntfy_title="Testing"
elif [ "$radarr_eventtype" == "Grab" ]; then
ntfy_tag=film_projector
ntfy_message+=" ("
ntfy_message+=$radarr_movie_year
ntfy_message+=")"
ntfy_message+=" ["
ntfy_message+=$radarr_release_quality
ntfy_message+="]"
elif [ "$radarr_eventtype" == "Download" ]; then
ntfy_tag=film_projector
ntfy_message+=" ("
ntfy_message+=$radarr_movie_year
ntfy_message+=")"
ntfy_message+=" ["
ntfy_message+=$radarr_moviefile_quality
ntfy_message+="]"
elif [ "$radarr_eventtype" == "ApplicationUpdate" ]; then
ntfy_tag=arrow_up
ntfy_message+="Radarr updated from "
ntfy_message+=$radarr_update_previousversion
ntfy_message+=" to "
ntfy_message+=$radarr_update_newversion
# ntfy_message+=" - Radarr message: "
# ntfy_message+=$radarr_update_message
elif [ "$radarr_eventtype" == "HealthIssue" ]; then
ntfy_tag=warning
ntfy_message+=$radarr_health_issue_message
else
ntfy_tag=information_source
fi
if [[ "$radarr_eventtype" == "Download" || "$radarr_eventtype" == "Grab" ]]; then
# Get the movie poster from Radarr
response=$(curl -X GET -H "Content-Type: application/json" -H "X-Api-Key: $radarr_api_key" "$radarr_url/api/v3/movie/$radarr_movie_id")
banner_image=$(echo "$response" | jq -r '.images[0].remoteUrl')
ntfy_post_data()
{
cat <<EOF
{
"topic": "$radarr_ntfy_topic",
"tags": ["$ntfy_tag"],
"icon": "$radarr_ntfy_icon",
"title": "Radarr: $radarr_eventtype",
"attach": "$banner_image",
"message": "$ntfy_title$ntfy_message",
"actions": [
{
"action": "view",
"label": "IMDB",
"url": "https://www.imdb.com/title/$radarr_movie_imdbid",
"clear": true
}
]
}
EOF
}
else
ntfy_post_data()
{
cat <<EOF
{
"topic": "$radarr_ntfy_topic",
"tags": ["$ntfy_tag"],
"icon": "$radarr_ntfy_icon",
"title": "Radarr: $radarr_eventtype",
"message": "$ntfy_title$ntfy_message"
}
EOF
}
fi
curl -H "Accept: application/json" \
-H "Content-Type:application/json" \
-H "$ntfy_auth" -X POST --data "$(ntfy_post_data)" $ntfy_url