Update QueueCleaner.bash

This commit is contained in:
RandomNinjaAtk 2023-03-18 10:52:06 -04:00 committed by GitHub
parent 8b82a29dce
commit 19118b8de8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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