Skip to content

Instantly share code, notes, and snippets.

@quaxim
Created June 11, 2019 19:25
Show Gist options
  • Save quaxim/72ac709678e9cb0deffc0ce419a1eed0 to your computer and use it in GitHub Desktop.
Save quaxim/72ac709678e9cb0deffc0ce419a1eed0 to your computer and use it in GitHub Desktop.
Rename all movies in Radarr
#!/bin/bash
#
# Quick and dirty script to hit the Radarr API and rename any movies ...
RADARR_API_KEY="xxxxxxxx"
RADARR_HOST="127.0.0.1"
RADARR_PORT="7878"
################################################################################################
jqInstalled() {
if ! [ -x "$(command -v jq)" ]; then
echo 'Please install the JQ tool to: [/usr/bin/jq], before running this script. Download JQ at: https://stedolan.github.io/jq/' >&2
exit 1
fi
}
# Check JQ Installed first..
jqInstalled
echo "NB: Script may take some time to execute if you have thousands of movies in Radarr, please be patient ..."
TOTALITEMS=`curl -s -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-Api-Key: $RADARR_API_KEY" \
-X GET http://$RADARR_HOST:$RADARR_PORT/api/movie`
i=0
total=`echo $TOTALITEMS | jq '. | length'`
for row in $(echo "${TOTALITEMS}" | jq -r '.[] | @base64'); do
_jq() {
echo ${row} | /usr/bin/base64 --decode | /usr/bin/jq -r ${1}
}
i=$((i + 1))
MOVIENAME=`echo $(_jq '.title')`
DOWNLOADED=`echo $(_jq '.downloaded')`
ID=`echo $(_jq '.id')`
FILENAME=`echo $(_jq '.movieFile.relativePath')`
echo "Processing: $i/$total - '$MOVIENAME'"
if [ "$DOWNLOADED" == "true" ]; then
if [[ $FILENAME = *"PP-SHRUNK"* ]]; then
echo "File has been post-processed by ffmpeg - do not rename."
else
RENAME_RESPONSE=`curl -s -H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-Api-Key: $RADARR_API_KEY" \
-X GET http://$RADARR_HOST:$RADARR_PORT/api/renameMovie?movieId=$ID`
FILE_ID=`echo $RENAME_RESPONSE | jq '.[].movieFileId'`
curl -s "http://$RADARR_HOST:$RADARR_PORT/api/command" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "X-Api-Key: $RADARR_API_KEY" \
--data-binary "{\"name\":\"renameMovieFiles\",\"movieId\":$ID,\"files\":[$FILE_ID]}" >> /dev/null
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment