@ -1,5 +1,5 @@
#!/usr/bin/env bash
scriptVersion = "1.0.00 3 "
scriptVersion = "1.0.00 4 "
if [ -z " $arrUrl " ] || [ -z " $arrApiKey " ] ; then
arrUrlBase = " $( cat /config/config.xml | xq | jq -r .Config.UrlBase) "
@ -23,37 +23,31 @@ if [ -f "/config/logs/QueueCleaner.txt" ]; then
find /config/logs -type f -name "QueueCleaner.txt" -size +1024k -delete
fi
touch "/config/logs/QueueCleaner.txt"
chmod 666 "/config/logs/QueueCleaner.txt "
exec & > >( tee -a "/config/logs/QueueCleaner.txt" )
arrQueueData = " $( curl -s " $arrUrl /api/v3/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownSeriesItems=true&apikey= ${ arrApiKey } " | jq -r .records[ ] ) "
arrQueueIds = $( echo " $arrQueueData " | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id' )
arrQueueIdsCount = $( echo " $arrQueueData " | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id' | wc -l)
if [ $arrQueueIdsCount -eq 0 ] ; then
log "No items in queue to clean up... "
els e
for queueId in $( echo $arrQueueIds ) ; do
arrQueueItemData = " $( echo " $arrQueueData " | jq -r " select(.id== $queueId ) " ) "
arrQueueItemTitle = " $( echo " $arrQueueItemData " | jq -r .title) "
log " Removing Failed Queue Item ID: $queueId ( $arrQueueItemTitle ) from Sonarr... "
curl -sX DELETE " $arrUrl /api/v3/queue/ $queueId ?removeFromClient=true&blocklist=true&apikey= ${ arrApiKey } "
done
fi
arrQueueData = " $( curl -s " $arrUrl /api/v3/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownSeriesItems=true&apikey= ${ arrApiKey } " | jq -r .records[ ] ) "
arrQueueIds = $( echo " $arrQueueData " | jq -r 'select(.status=="failed") | select(.trackedDownloadStatus=="warning") | .id' )
arrQueueIdsCount = $( echo " $arrQueueData " | jq -r 'select(.status=="failed") | select(.trackedDownloadStatus=="warning") | .id' | wc -l)
if [ $arrQueueIdsCount -eq 0 ] ; then
log "No items in queue to clean up..."
else
CleanerProcess ( ) {
arrQueueData = " $( curl -s " $arrUrl /api/v3/queue?page=1&pagesize=200&sortDirection=descending&sortKey=progress&includeUnknownSeriesItems=true&apikey= ${ arrApiKey } " | jq -r .records[ ] ) "
arrQueueIds = $( echo " $arrQueueData " | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id' )
arrQueueIdsCount = $( echo " $arrQueueData " | jq -r 'select(.status=="completed") | select(.trackedDownloadStatus=="warning") | .id' | wc -l)
if [ $arrQueueIdsCount -eq 0 ] ; then
log "No items in queue to clean up..."
else
for queueId in $( echo $arrQueueIds ) ; do
arrQueueItemData = " $( echo " $arrQueueData " | jq -r " select(.id== $queueId ) " ) "
arrQueueItemTitle = " $( echo " $arrQueueItemData " | jq -r .tit le) "
arrEpisodeData = " $( curl -s " $arrUrl /api/v3/episode/ $queueId ?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/comman d" -X POST -H 'C ont ent-Type: application/json' -H " X-Api-Key: $arrApiKey " --data-raw " {\"name\":\"RefreshSeries\",\"seriesId\": $arrEpisodeSeriesId } " )
continue
else
log " Removing Failed Queue Item ID: $queueId ( $arrQueueItemTitle ) from Sonarr... "
curl -sX DELETE " $arrUrl /api/v3/queue/ $queueId ?removeFromClient=true&blocklist=true&apikey= ${ arrApiKey } "
fi
done
f i
}
for queueId in $( echo $arrQueueIds ) ; do
arrQueueItemData = " $( echo " $arrQueueData " | jq -r " select(.id== $queueId ) " ) "
arrQueueItemTitle = " $( echo " $arrQueueItemData " | jq -r .title) "
log " Removing Failed Queue Item ID: $queueId ( $arrQueueItemTitle ) from Sonarr... "
curl -sX DELETE " $arrUrl /api/v3/queue/ $queueId ?removeFromClient=true&blocklist=true&apikey= ${ arrApiKey } "
done
fi
CleanerProcess
exit