Skip to content

Instantly share code, notes, and snippets.

@elneruda
Last active June 23, 2023 01:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elneruda/d2d456a3c2d511915294da68837afa4f to your computer and use it in GitHub Desktop.
Save elneruda/d2d456a3c2d511915294da68837afa4f to your computer and use it in GitHub Desktop.
Radarr Sonarr Slack Custom Script : Rich slack notifications, episode & movie link
#!/bin/bash
SLACK_URL=$1
RADARR_API_URL="$2/api"
RADARR_API_KEY=$3
post_to_slack() {
curl --silent -X POST --data "payload={\"text\": \"${1}\", \"unfurl_links\": true, \"mrkdwn\": true}" ${SLACK_URL}
}
radarrHistory=$(curl --silent "${RADARR_API_URL}/history/?apikey=${RADARR_API_KEY}&page=1&sortKey=date&sortDir=desc&pageSize=20" -X GET -k)
radarrIndexer=$(echo $radarrHistory | jq -r '.records[] | select(.downloadId == "'${radarr_download_id}'") .data.indexer | select(.!=null)')
title="*${radarr_movie_title}* [${radarr_moviefile_quality}]"
link="https://www.themoviedb.org/movie/${radarr_movie_tmdbid}"
message=":package: ${title}\n:male-construction-worker: \`${radarrIndexer}\` _${radarr_moviefile_releasegroup}_\n:books: ${link}"
#echo $message
post_to_slack "${message}"
#!/bin/bash
SLACK_URL=$1
SONARR_API_URL="$2/api"
SONARR_API_KEY=$3
TVMAZE_API_URL="http://api.tvmaze.com/shows/${sonarr_series_tvmazeid}/episodebynumber?season=${sonarr_episodefile_seasonnumber}&number=${sonarr_episodefile_episodenumbers}"
post_to_slack() {
curl --silent -X POST --data "payload={\"text\": \"${1}\", \"unfurl_links\": true, \"mrkdwn\": true}" ${SLACK_URL}
}
sonarrSerieQuery="${SONARR_API_URL}/episode/?apikey=${SONARR_API_KEY}&seriesId=${sonarr_series_id}"
sonarrSerie=$(curl --silent "${sonarrSerieQuery}" -X GET -k)
sonarrSerie=$(echo $sonarrSerie | tr -d '\n' | tr -d '\r' | tr -d '\b')
sonarrEpisodeId=$(echo $sonarrSerie | jq -r '.[] | select(.episodeFileId == '${sonarr_episodefile_id}') .id | select(.!=null)')
sonarrEpisodeQuery="${SONARR_API_URL}/history/?apikey=${SONARR_API_KEY}&episodeId=${sonarrEpisodeId}&sortKey=date"
sonarrEpisode=$(curl --silent "${sonarrEpisodeQuery}" -X GET -k)
sonarrEpisode=$(echo $sonarrEpisode | tr -d '\n' | tr -d '\r' | tr -d '\b')
sonarrIndexer=$(echo $sonarrEpisode | jq -r '.records[] | select(.downloadId == "'${sonarr_download_id}'") .data.indexer | select(.!=null)')
title="*${sonarr_series_title} - ${sonarr_episodefile_seasonnumber}x${sonarr_episodefile_episodenumbers} - ${sonarr_episodefile_episodetitles}* [${sonarr_episodefile_quality}]"
episode=$(curl --silent ${TVMAZE_API_URL} -X GET -k)
link=$(echo $episode | jq -r '.url')
message=":package: ${title}\n:male-construction-worker: \`${sonarrIndexer}\` _${sonarr_episodefile_releasegroup}_\n:books: ${link}"
#echo $message
post_to_slack "${message}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment