Shell
#!/usr/bin/env bash
###########################################################################
## Copyright (C) Wizardry and Steamworks 2024 - License: GNU GPLv3 ##
###########################################################################
# Inspired by Francesco Giannelli @ #
# https://github.com/Sonarr/Sonarr/issues/958 #
###########################################################################
# #
# This script is meant to be executed via cron and will remove all broken #
# downloads from the queue, optionally remove the downloads from the #
# download client and additionally blacklist the release. #
# #
# The motiviation behind this script is the inability of the *arr servers #
# to automatically detect and remove stalled downloads or outright broken #
# releases from their own queue or the download client. #
# #
# In order to use, change the parameters in the configuration settings #
# and run this script periodically via cron. #
# #
###########################################################################
###########################################################################
## CONFIGURATION ##
###########################################################################
API_KEY=c0f52b1421be43889e538ef393595faa
HOST=http://127.0.0.1:8686/lidarr
BLOCKLIST=true
REMOVE=false
###########################################################################
## INTERNALS ##
###########################################################################
DATA=`curl -s -X GET "$HOST/api/v1/queue?apikey=$API_KEY"`
# Stalled
A=`echo "$DATA" | jq '.records[] | select(.errorMessage | try contains("The download is stalled with no connections")) | .id' | uniq`
# Import failed
B=`echo "$DATA" | jq '.records[] | select(.trackedDownloadState | try contains("importFailed")) | .id' | uniq`
IFS=$'\n'
for ID in $A $B; do
curl -X DELETE "$HOST/api/v1/queue/$ID?&apikey=$API_KEY&removeFromClient=$REMOVE&blocklist=$BLOCKLIST" 2>/dev/null 2>&1
done