Skip to content

Instantly share code, notes, and snippets.

@subzero79
Created March 29, 2016 09:45
Show Gist options
  • Save subzero79/34dfe0ca8028ce3874f7 to your computer and use it in GitHub Desktop.
Save subzero79/34dfe0ca8028ce3874f7 to your computer and use it in GitHub Desktop.
#!/bin/bash
filePath="${1}"
##SONARR API CONSULT
SONARR_HOST="10.10.10.12"
SONARR_PORT="8989"
SONARR_API="5215023779d84ad391719fc703bba5ba"
CURL_API="X-Api-Key: $SONARR_API"
URL_SONARR="http://$SONARR_HOST:$SONARR_PORT/api/"
call_sonarr () {
curl -s -G $URL_SONARR"$1" -H "$CURL_API" --compressed
}
sonarr_unmonitor () {
curl -s "${URL_SONARR}"episode \
-X PUT -H "${CURL_API}" --compressed \
--data-binary '{"seriesId":"'"$1"'","id":"'"$2"'","monitored":false}'
}
urldecode () {
sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"
}
parse_info () {
fileName=$(basename "`echo "${filePath}" | urldecode`")
IFS=$OLD_IFS
IFS=$'\n'
video_info=( $(guessit -j "${fileName}" | jq -sr '.[]| .title, .season, .episode, .type') )
IFS=$OLD_IFS
showTitle="${video_info[0]}"
showSeason="${video_info[1]}"
showEpisode="${video_info[2]}"
mediaType="${video_info[3]}"
if [[ ! ${mediaType} == episode ]];then
echo "Video is not a TV Show"
exit
fi
echo ${video_info[@]}
}
get_sonarr_info () {
sonarr_series_all=$(call_sonarr series)
sonarr_series_id=$(printf "%s " "${sonarr_series_all[@]}" | jq \
-r --arg title "${showTitle}" '.[] | select(.title==$title ) | .id ')
sonarr_episode_array=$(call_sonarr episode?seriesId=$sonarr_series_id)
sonarr_episode_id=$(printf '%s ' $sonarr_episode_array | jq \
--argjson season_number ${showSeason} \
--argjson episode_number ${showEpisode} \
'.[] | select(.seasonNumber==$season_number) | select(.episodeNumber==$episode_number) | .id')
}
parse_info
get_sonarr_info
echo $sonarr_episode_id $sonarr_series_id
sonarr_unmonitor $sonarr_series_id $sonarr_episode_id &>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment