Last active
March 22, 2020 18:34
-
-
Save TGM/ae002415274825420f772f0ff27f4172 to your computer and use it in GitHub Desktop.
radarr-cleanup.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# based upon https://github.com/Radarr/Radarr/wiki/Mass-Delete-via-API | |
# and https://gist.github.com/pstadler/bc0afefe35f608e9552e764b31f45f19 | |
RADARR_API_KEY= | |
RADARR_API_IP= | |
RADARR_API_PORT=7878 | |
OLDER_THEN=365*24*3600 | |
DELETE_FILES=true | |
BAN_DELETED=true | |
# delete movies that were added over X time ago | |
RADARR_MOVIE_LIST="$(curl -s -X GET 'http://'$RADARR_API_IP':'$RADARR_API_PORT'/api/movie/' -H 'X-Api-Key: '$RADARR_API_KEY)" | |
RADARR_OLD_MOVIES="$(echo "$RADARR_MOVIE_LIST" | jq '.[] | select ((.movieFile.dateAdded <= ((now - ('$OLDER_THEN')) | gmtime | todate)) and .hasFile ) | .id' )" | |
for i in $RADARR_OLD_MOVIES; do | |
curl -s -X DELETE "http://$RADARR_API_IP:$RADARR_API_PORT/api/movie/$i?deleteFiles=$DELETE_FILES&addExclusion=$BAN_DELETED" -H "X-Api-Key: $RADARR_API_KEY" | |
done | |
# delete unmonitored movies | |
RADARR_UNMONITORED="$(echo "$RADARR_MOVIE_LIST" | jq '.[] | select(.monitored == false) | .id' )" | |
for id in $RADARR_UNMONITORED; do | |
curl -s -X DELETE "http://$RADARR_API_IP:$RADARR_API_PORT/api/movie/$id?deleteFiles=$DELETE_FILES&addExclusion=$BAN_DELETED" -H "X-Api-Key: $RADARR_API_KEY" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment