diff --git a/universal/services/QueueCleaner b/universal/services/QueueCleaner index 55447fb..dcc360f 100644 --- a/universal/services/QueueCleaner +++ b/universal/services/QueueCleaner @@ -1,5 +1,5 @@ #!/usr/bin/with-contenv bash -scriptVersion="1.7" +scriptVersion="1.8" scriptName="QueueCleaner" #### Import Settings @@ -28,35 +28,44 @@ verifyConfig () { } QueueCleanerProcess () { + arrQueueData="" # Sonarr - if [ "$arrPort" == "8989" ]; then + if [ -z "$arrQueueData" ]; then arrQueueData="$(curl -s "$arrUrl/api/v3/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownSeriesItems=true&apikey=${arrApiKey}" | jq -r .records[])" fi # Radarr - if [ "$arrPort" == "7878" ]; then - arrQueueData="$(curl -s "$arrUrl/api/v3/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownMovieItems=true&apikey=${arrApiKey}" | jq -r .records[])" + if [ -z "$arrQueueData" ]; then + arrQueueData="$(curl -s "$arrUrl/api/v3/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownMovieItems=true&apikey=${arrApiKey}" | jq -r .records[])" fi # Lidarr - if [ "$arrPort" == "8686" ]; then + if [ -z "$arrQueueData" ]; then arrQueueData="$(curl -s "$arrUrl/api/v1/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownArtistItems=true&apikey=${arrApiKey}" | jq -r .records[])" fi # Readarr - if [ "$arrPort" == "8787" ]; then + if [ -z "$arrQueueData" ]; then arrQueueData="$(curl -s "$arrUrl/api/v1/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownAuthorItems=true&apikey=${arrApiKey}" | jq -r .records[])" fi - + arrQueueIdCount=$(echo "$arrQueueData" | jq -r ".id" | wc -l) arrQueueCompletedIds=$(echo "$arrQueueData" | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id') - arrQueueIdsCompletedCount=$(echo "$arrQueueData" | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id' | wc -l) + arrQueueIdsCompletedCount=$(echo -n "$arrQueueCompletedIds" | wc -l) arrQueueFailedIds=$(echo "$arrQueueData" | jq -r 'select(.status=="failed") | .id') - arrQueueIdsFailedCount=$(echo "$arrQueueData" | jq -r 'select(.status=="failed") | .id' | wc -l) - arrQueuedIds=$(echo "$arrQueueCompletedIds"; echo "$arrQueueFailedIds") - arrQueueIdsCount=$(( $arrQueueIdsCompletedCount + $arrQueueIdsFailedCount )) + arrQueueIdsFailedCount=$(echo -n "$arrQueueFailedIds" | wc -l) + arrQueueStalledIds=$(echo "$arrQueueData" | jq -r 'select(.status=="stalled") | .id') + arrQueueIdsStalledount=$(echo -n "$arrQueueStalledIds" | wc -l) + arrQueuedIds=$(echo "$arrQueueCompletedIds"; echo "$arrQueueFailedIds"; echo "$arrQueueStalledIds") + arrQueueIdsCount=$(( $arrQueueIdsCompletedCount + $arrQueueIdsFailedCount + $arrQueueIdsStalledount )) + + # Debugging + #echo "$arrQueueIdsCount :: $arrQueueIdsCompletedCount + $arrQueueIdsFailedCount + $arrQueueIdsStalledount" + #echo "$arrQueueCompletedIds" + #echo "$arrQueueFailedIds" + #echo "$arrQueueStalledIds" if [ $arrQueueIdsCount -eq 0 ]; then - log "No items in queue to clean up" + log "$arrQueueIdCount items in queue, no items in queue to clean up" else for queueId in $(echo $arrQueuedIds); do arrQueueItemData="$(echo "$arrQueueData" | jq -r "select(.id==$queueId)")"