From 19118b8de85da7e72ef5e54999035cc7e8de544c Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Sat, 18 Mar 2023 10:52:06 -0400 Subject: [PATCH] Update QueueCleaner.bash --- QueueCleaner.bash | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/QueueCleaner.bash b/QueueCleaner.bash index b4dbf84..3588236 100644 --- a/QueueCleaner.bash +++ b/QueueCleaner.bash @@ -1,15 +1,17 @@ #!/usr/bin/env bash scriptVersion="1.0.0" -######## Dependancy Installation -pip install --upgrade --no-cache-dir -U yq +######## Package dependencies installation +pip install --upgrade --no-cache-dir -U yq &>/dev/null +# Logging output function log () { m_time=`date "+%F %T"` echo $m_time" :: QueueCleaner :: $scriptVersion :: "$1 } QueueCleanerProcess () { + # Get Arr App information if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" if [ "$arrUrlBase" == "null" ]; then @@ -44,7 +46,6 @@ QueueCleanerProcess () { arrQueueData="$(curl -s "$arrUrl/api/v1/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownArtistItems=true&apikey=${arrApiKey}" | jq -r .records[])" fi - 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) arrQueueFailedIds=$(echo "$arrQueueData" | jq -r 'select(.status=="failed") | .id') @@ -58,22 +59,36 @@ QueueCleanerProcess () { for queueId in $(echo $arrQueuedIds); do arrQueueItemData="$(echo "$arrQueueData" | jq -r "select(.id==$queueId)")" arrQueueItemTitle="$(echo "$arrQueueItemData" | jq -r .title)" - log "Removing Failed Queue Item ID: $queueId ($arrQueueItemTitle) from Radarr..." + if [ "$arrName" == "Sonarr" ]; then + arrEpisodeId="$(echo "$arrQueueItemData" | jq -r .episodeId)" + arrEpisodeData="$(curl -s "$arrUrl/api/v3/episode/$arrEpisodeId?apikey=${arrApiKey}")" + arrEpisodeTitle="$(echo "$arrEpisodeData" | jq -r .title)" + arrEpisodeSeriesId="$(echo "$arrEpisodeData" | jq -r .seriesId)" + if [ "$arrEpisodeTitle" == "TBA" ]; then + log "ERROR :: Episode title is \"$arrEpisodeTitle\" and prevents auto-import, refreshing series..." + refreshSeries=$(curl -s "$arrUrl/api/v3/command" -X POST -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" --data-raw "{\"name\":\"RefreshSeries\",\"seriesId\":$arrEpisodeSeriesId}") + continue + fi + fi + log "Removing Failed Queue Item ID: $queueId ($arrQueueItemTitle) from $arrName..." deleteItem=$(curl -sX DELETE "$arrUrl/api/v3/queue/$queueId?removeFromClient=true&blocklist=true&apikey=${arrApiKey}") done fi } -log "Waiting for $arrName to startup, sleeping for 2 minutes..." -sleep 2m -log "Starting Script...." -for (( ; ; )); do - let i++ - - QueueCleanerProcess - - log "Script sleeping for 15 minutes..." - sleep 15m -done +arrName="$(cat /config/config.xml | xq | jq -r .Config.InstanceName)" +if [ "$arrName" == "Sonarr" ] || [ "$arrName" == "Radarr" ] || [ "$arrName" == "Lidarr" ]; then + log "Waiting for $arrName to startup, sleeping for 2 minutes..." + #sleep 2m + log "Starting Script...." + for (( ; ; )); do + let i++ + QueueCleanerProcess + log "Processing complete, sleeping for 15 minutes..." + sleep 15m + done +else + log "ERROR :: Arr app not detected, exiting..." +fi exit