🐛 fix sonarr

This commit is contained in:
auricom
2023-09-09 21:28:22 +02:00
parent 213972205c
commit 4e373d9d5f
2 changed files with 17 additions and 24 deletions

View File

@@ -1,12 +1,11 @@
#!/usr/bin/env bash
PUSHOVER_DEBUG="${PUSHOVER_DEBUG:-"true"}"
# kubectl port-forward service/sonarr -n default 8989:8989
# export PUSHOVER_APP_URL="";
# kubectl port-forward service/sonarr -n default 8989:80
# export PUSHOVER_TOKEN="";
# export PUSHOVER_USER_KEY="";
# export sonarr_eventtype=Download;
# ./notify.sh
# ./pushover-notify.sh
CONFIG_FILE="/config/config.xml" && [[ "${PUSHOVER_DEBUG}" == "true" ]] && CONFIG_FILE="config.xml"
ERRORS=()
@@ -15,15 +14,12 @@ ERRORS=()
# Discoverable variables
#
# shellcheck disable=SC2086
PUSHOVER_STARR_PORT="$(xmlstarlet sel -t -v "//Port" -nl ${CONFIG_FILE})" && [[ -z "${PUSHOVER_STARR_PORT}" ]] && ERRORS+=("PUSHOVER_STARR_PORT not defined")
PUSHOVER_STARR_APIKEY="$(xmlstarlet sel -t -v "//ApiKey" -nl ${CONFIG_FILE})" && [[ -z "${PUSHOVER_STARR_APIKEY}" ]] && ERRORS+=("PUSHOVER_STARR_APIKEY not defined")
PUSHOVER_STARR_INSTANCE_NAME="$(xmlstarlet sel -t -v "//InstanceName" -nl ${CONFIG_FILE})" && [[ -z "${PUSHOVER_STARR_INSTANCE_NAME}" ]] && ERRORS+=("PUSHOVER_STARR_INSTANCE_NAME not defined")
#
# Configurable variables
#
# Required
PUSHOVER_APP_URL="${PUSHOVER_APP_URL:-}" && [[ -z "${PUSHOVER_APP_URL}" ]] && ERRORS+=("PUSHOVER_APP_URL not defined")
PUSHOVER_USER_KEY="${PUSHOVER_USER_KEY:-}" && [[ -z "${PUSHOVER_USER_KEY}" ]] && ERRORS+=("PUSHOVER_USER_KEY not defined")
PUSHOVER_TOKEN="${PUSHOVER_TOKEN:-}" && [[ -z "${PUSHOVER_TOKEN}" ]] && ERRORS+=("PUSHOVER_TOKEN not defined")
# Optional
@@ -53,41 +49,38 @@ fi
#
if [[ "${sonarr_eventtype:-}" == "Test" ]]; then
PUSHOVER_TITLE="Test Notification"
PUSHOVER_MESSAGE="Howdy this is a test notification from ${PUSHOVER_STARR_INSTANCE_NAME}"
PUSHOVER_MESSAGE="Howdy this is a test notification from ${sonarr_instancename:-Sonarr}"
fi
#
# Send notification on Download or Upgrade
#
if [[ "${sonarr_eventtype:-}" == "Download" ]]; then
printf -v PUSHOVER_TITLE "%s - S%02dE%02d - %s [%s]" \
"${sonarr_series_title:-"That '70s Show"}" \
printf -v PUSHOVER_TITLE "New Episode %s" "${sonarr_eventtype:-Download}"
printf -v PUSHOVER_MESSAGE "<b>%s (S%02dE%02d)</b><small>\n%s</small><small>\n\n<b>Quality:</b> %s</small><small>\n<b>Client:</b> %s</small><small>\n<b>Upgrade:</b> %s</small>" \
"${sonarr_series_title:-"Mystery Science Theater 3000"}" \
"${sonarr_episodefile_seasonnumber:-"8"}" \
"${sonarr_episodefile_episodenumbers:-"22"}" \
"${sonarr_episodefile_episodetitles:-"That '70s Finale"}" \
"${sonarr_episodefile_quality:-"Bluray-720p"}"
printf -v PUSHOVER_MESSAGE "%s" \
"$(curl --silent --header "X-Api-Key:${PUSHOVER_STARR_APIKEY}" "http://localhost:${PUSHOVER_STARR_PORT}/api/v3/episode?seriesId=${sonarr_series_id:-"1653"}" \
| jq -r ".[] | select(.episodeFileId==${sonarr_episodefile_id:-"167750"}) | .overview")"
printf -v PUSHOVER_URL "https://%s/series/%s" \
"${PUSHOVER_APP_URL}" \
"$(curl --silent --header "X-Api-Key:${PUSHOVER_STARR_APIKEY}" "http://localhost:${PUSHOVER_STARR_PORT}/api/v3/series/${sonarr_series_id:-"1653"}" \
| jq -r ".titleSlug")"
printf -v PUSHOVER_URL_TITLE "View series in %s" \
"${PUSHOVER_STARR_INSTANCE_NAME}"
"${sonarr_episodefile_episodenumbers:-"20"}" \
"${sonarr_episodefile_episodetitles:-"Space Mutiny"}" \
"${sonarr_episodefile_quality:-"DVD"}" \
"${sonarr_download_client:-"qbittorrent"}" \
"${sonarr_isupgrade:-"False"}"
printf -v PUSHOVER_URL "%s/series/%s" "${sonarr_applicationurl:-localhost}" "${sonarr_series_titleslug:-""}"
printf -v PUSHOVER_URL_TITLE "View series in %s" "${sonarr_instancename:-Sonarr}"
fi
notification=$(jq -n \
--arg token "${PUSHOVER_TOKEN}" \
--arg user "${PUSHOVER_USER_KEY}" \
--arg title "${PUSHOVER_TITLE}" \
--arg message "${PUSHOVER_MESSAGE:-"Unable to obtain plot summary"}" \
--arg message "${PUSHOVER_MESSAGE}" \
--arg url "${PUSHOVER_URL}" \
--arg url_title "${PUSHOVER_URL_TITLE}" \
--arg priority "${PUSHOVER_PRIORITY}" \
--arg sound "${PUSHOVER_SOUND}" \
--arg device "${PUSHOVER_DEVICE}" \
'{token: $token, user: $user, title: $title, message: $message, url: $url, url_title: $url_title, priority: $priority, sound: $sound, device: $device}' \
--arg html "1" \
'{token: $token, user: $user, title: $title, message: $message, url: $url, url_title: $url_title, priority: $priority, sound: $sound, device: $device, html: $html}' \
)
status_code=$(curl \