Last active
March 20, 2016 05:40
-
-
Save subzero79/a0f1eee9b256ba6b78df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##KODI API RETRIEVE | |
XBMCUSER="xbmc" | |
XBMCPWD="xbmc" | |
KODI_HOST="10.10.10.11:8080" | |
Recent_added=$(curl -s -H 'content-type: application/json;' http://${XBMCUSER}:${XBMCPWD}@${KODI_HOST}/jsonrpc \ | |
--data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.GetRecentlyAddedEpisodes", | |
"params": { "properties": [ "showtitle","episode","season","playcount" ], | |
"limits": { "start" : 0, "end": 25 } }, "id": 1 }') | |
OLD_IFS=$IFS | |
IFS=$'\n' | |
watched_showtitle=(`printf "%s " ${Recent_added[@]} | jq -rs '.[].result.episodes[] | select(.playcount > 0) | .showtitle'`) | |
watched_season=(`printf "%s " ${Recent_added[@]} | jq -rs '.[].result.episodes[] | select(.playcount > 0) | .season'`) | |
watched_episode=(`printf "%s " ${Recent_added[@]} | jq -rs '.[].result.episodes[] | select(.playcount > 0) | .episode'`) | |
IFS=$OLD_IFS | |
##SONARR API CONSULT | |
SONARR_HOST="10.10.10.12" | |
SONARR_PORT="8989" | |
SONARR_API="TOKEN_KEY" | |
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 $1 | |
} | |
##SONARR TOGGLING MONITORING ROUTINE | |
sonarr_toggle_monitor () { | |
j=0 | |
for i in "${watched_showtitle[@]}" | |
do | |
sonarr_series_id=$(printf "%s " "${sonarr_series_all[@]}" | jq -r --arg title "${i}" '.[] | 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 ${watched_season[$j]} --argjson episode_number ${watched_episode[$j]} \ | |
'.[] | select(.seasonNumber==$season_number) | select(.episodeNumber==$episode_number) | .id') | |
sonarr_episode_id_monitored=$(printf '%s ' $sonarr_episode_array | \ | |
jq --argjson season_number ${watched_season[$j]} --argjson episode_number ${watched_episode[$j]} \ | |
'.[] | select(.seasonNumber==$season_number) | select(.episodeNumber==$episode_number) | select(.monitored==true) | .id') | |
printf "%s\n" "${i}" | |
printf "%s\n" "Sonarr serie ID: ${sonarr_series_id}" | |
printf "%s\n" "Sonarr episode ID: ${sonarr_episode_id}" | |
printf "%s\n" "Season: ${watched_season[$j]} " | |
printf "%s\n" "Episode: ${watched_episode[$j]} " | |
printf "%s\n" "Sonarr episode ID: ${sonarr_episode_id}" | |
if [ -z $sonarr_episode_id_monitored ];then | |
printf "%s\n" "${i} - ${watched_season[$j]}x${watched_episode[$j]} is already unmonitored" | |
else | |
printf "%s\n" "Unmonitoring ${i} - ${watched_season[$j]}x${watched_episode[$j]}" | |
sonarr_unmonitor '{"seriesId":"'"$sonarr_series_id"'","id":"'"$sonarr_episode_id"'","monitored":false}' &> /dev/null | |
fi | |
((j++)) | |
done | |
} | |
sonarr_series_all=$(call_sonarr series) | |
sonarr_toggle_monitor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment