99 lines
2.7 KiB
Bash
Executable File
99 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
NTFY_SERVER_URL=${NTFY_SERVER_URL:-ntfy.sh}
|
|
NTFY_CHANNEL=${NTFY_CHANNEL:-jellyfin_notications}
|
|
ICON_URL=${ICON_URL:-https://raw.githubusercontent.com/NX211/homer-icons/master}
|
|
TMDB_URL="https://www.themoviedb.org"
|
|
|
|
notify() {
|
|
# message title action tags priority
|
|
curl -s \
|
|
-H "Title: ${2}" \
|
|
-H "Icon: ${ICON_URL}/png/jellyfin.png" \
|
|
-H "Actions: ${3}" \
|
|
-H "Tags: ${4}" \
|
|
-H "Priority: ${5}" \
|
|
-d "${1}" "${NTFY_SERVER_URL}/${NTFY_CHANNEL}"
|
|
}
|
|
|
|
get_value() {
|
|
jq "$1" <(echo "$JSON") | tr -d '"'
|
|
}
|
|
|
|
JSON=$1
|
|
ARTIST=$(get_value ".Artist")
|
|
YEAR=$(get_value ".Year")
|
|
TYPE=$(get_value ".NotificationType")
|
|
ITEM_TYPE=$(get_value ".ItemType")
|
|
ITEM_NAME=$(get_value ".Name")
|
|
NOTIFICATION_USERNAME=$(get_value ".NotificationUsername")
|
|
PLUGIN_NAME=$(get_value ".PluginName")
|
|
PLUGIN_VERSION=$(get_value ".PluginVersion")
|
|
SERVER=$(get_value .ServerName)
|
|
VERSION=$(get_value .ServerVersion)
|
|
SERIES_NAME=$(get_value .SeriesName)
|
|
EPISODE_NUMBER=$(get_value .EpisodeNumber00)
|
|
SEASON_NUMBER=$(get_value .SeasonNumber00)
|
|
PROVIDER_TMDB=$(get_value .Provider_tmdb)
|
|
PROVIDER_TVDB=$(get_value .Provider_tvdb)
|
|
TAGS="media"
|
|
|
|
case "$TYPE" in
|
|
PluginUninstalled)
|
|
PRIORITY="2"
|
|
MESSAGE="Plugin $PLUGIN_NAME $PLUGIN_VERSION was uninstalled."
|
|
;;
|
|
ItemAdded)
|
|
PRIORITY="2"
|
|
case "$ITEM_TYPE" in
|
|
MusicAlbum)
|
|
[ "$ARTIST" = "null" ] && ARTIST="Various Artists"
|
|
MESSAGE="New music has been added: $ITEM_NAME by $ARTIST ($YEAR)."
|
|
;;
|
|
Episode)
|
|
MESSAGE="$SERIES_NAME ${SEASON_NUMBER}x${EPISODE_NUMBER} - $ITEM_NAME ($YEAR) has been added."
|
|
ACTION="view, TMDB, ${TMDB_URL}/series/${PROVIDER_TVDB}"
|
|
;;
|
|
Movie)
|
|
MESSAGE="$ITEM_NAME ($YEAR) has been added."
|
|
ACTION="view, TMDB, ${TMDB_URL}/movie/${PROVIDER_TMDB}"
|
|
;;
|
|
# ignore these
|
|
Audio | Season | Series)
|
|
;;
|
|
*)
|
|
MESSAGE="Item of type $ITEM_TYPE with the name $ITEM_NAME has been added to the library."
|
|
;;
|
|
esac
|
|
;;
|
|
AuthenticationFailure)
|
|
PRIORITY="5"
|
|
MESSAGE="Authentication for user $NOTIFICATION_USERNAME has failed."
|
|
;;
|
|
PendingRestart)
|
|
PRIORITY="4"
|
|
MESSAGE="Server needs to be restarted."
|
|
;;
|
|
UserDeleted)
|
|
PRIORITY="3"
|
|
MESSAGE="User $NOTIFICATION_USERNAME has been deleted."
|
|
;;
|
|
UserLockedOut)
|
|
PRIORITY="5"
|
|
MESSAGE="User $NOTIFICATION_USERNAME has been locked out."
|
|
;;
|
|
*)
|
|
PRIORITY="3"
|
|
MESSAGE="Unrecognized NoticationType. See the logs."
|
|
;;
|
|
esac
|
|
|
|
# MESSAGE is empty if a NotificationType or ItemType was ignored
|
|
if [[ -z "${MESSAGE:-}" ]]; then
|
|
echo "MESSAGE is empty. Ignoring this notification."
|
|
exit 0
|
|
fi
|
|
|
|
notify "${MESSAGE:-Empty message.}" "Jellyfin $VERSION ($SERVER)" "${ACTION:-}" "${TAGS:-media}" "${PRIORITY:-3}"
|