#!/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=39d53f275e044cc99b03f5a1d636a780 HOST=http://127.0.0.1:8787/readarr 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