Update QueueCleaner.bash
This commit is contained in:
parent
8b82a29dce
commit
19118b8de8
1 changed files with 30 additions and 15 deletions
|
@ -1,15 +1,17 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
scriptVersion="1.0.0"
|
scriptVersion="1.0.0"
|
||||||
|
|
||||||
######## Dependancy Installation
|
######## Package dependencies installation
|
||||||
pip install --upgrade --no-cache-dir -U yq
|
pip install --upgrade --no-cache-dir -U yq &>/dev/null
|
||||||
|
|
||||||
|
# Logging output function
|
||||||
log () {
|
log () {
|
||||||
m_time=`date "+%F %T"`
|
m_time=`date "+%F %T"`
|
||||||
echo $m_time" :: QueueCleaner :: $scriptVersion :: "$1
|
echo $m_time" :: QueueCleaner :: $scriptVersion :: "$1
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueCleanerProcess () {
|
QueueCleanerProcess () {
|
||||||
|
# Get Arr App information
|
||||||
if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then
|
if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then
|
||||||
arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
|
arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
|
||||||
if [ "$arrUrlBase" == "null" ]; then
|
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[])"
|
arrQueueData="$(curl -s "$arrUrl/api/v1/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownArtistItems=true&apikey=${arrApiKey}" | jq -r .records[])"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
arrQueueCompletedIds=$(echo "$arrQueueData" | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id')
|
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 "$arrQueueData" | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id' | wc -l)
|
||||||
arrQueueFailedIds=$(echo "$arrQueueData" | jq -r 'select(.status=="failed") | .id')
|
arrQueueFailedIds=$(echo "$arrQueueData" | jq -r 'select(.status=="failed") | .id')
|
||||||
|
@ -58,22 +59,36 @@ QueueCleanerProcess () {
|
||||||
for queueId in $(echo $arrQueuedIds); do
|
for queueId in $(echo $arrQueuedIds); do
|
||||||
arrQueueItemData="$(echo "$arrQueueData" | jq -r "select(.id==$queueId)")"
|
arrQueueItemData="$(echo "$arrQueueData" | jq -r "select(.id==$queueId)")"
|
||||||
arrQueueItemTitle="$(echo "$arrQueueItemData" | jq -r .title)"
|
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}")
|
deleteItem=$(curl -sX DELETE "$arrUrl/api/v3/queue/$queueId?removeFromClient=true&blocklist=true&apikey=${arrApiKey}")
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
log "Waiting for $arrName to startup, sleeping for 2 minutes..."
|
arrName="$(cat /config/config.xml | xq | jq -r .Config.InstanceName)"
|
||||||
sleep 2m
|
if [ "$arrName" == "Sonarr" ] || [ "$arrName" == "Radarr" ] || [ "$arrName" == "Lidarr" ]; then
|
||||||
log "Starting Script...."
|
log "Waiting for $arrName to startup, sleeping for 2 minutes..."
|
||||||
for (( ; ; )); do
|
#sleep 2m
|
||||||
|
log "Starting Script...."
|
||||||
|
for (( ; ; )); do
|
||||||
let i++
|
let i++
|
||||||
|
|
||||||
QueueCleanerProcess
|
QueueCleanerProcess
|
||||||
|
log "Processing complete, sleeping for 15 minutes..."
|
||||||
log "Script sleeping for 15 minutes..."
|
|
||||||
sleep 15m
|
sleep 15m
|
||||||
done
|
done
|
||||||
|
else
|
||||||
|
log "ERROR :: Arr app not detected, exiting..."
|
||||||
|
fi
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
Loading…
Reference in a new issue