From 2e698c6d03d51173ef6f4d5b844bb0c967d1852c Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Fri, 7 Jun 2024 10:46:19 +0000 Subject: [PATCH] v1.8 - Add support for stalled downloads cleanup #267 - Based on reviewing this PR, I have updated the script to accommodate the request without the need for a complete re-write and removal of existing functionality. Additionally, this should now support any port... Has had limited testing... --- universal/services/QueueCleaner | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) 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)")"