Skip to content

Instantly share code, notes, and snippets.

@rjfpeters
Created June 2, 2020 06:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjfpeters/5a8553f9c1ffcc4d8dbcb6941c71fb64 to your computer and use it in GitHub Desktop.
Save rjfpeters/5a8553f9c1ffcc4d8dbcb6941c71fb64 to your computer and use it in GitHub Desktop.
Script to update the movies in the radarr library
#!/bin/sh
RADARR_API_KEY=""
RADARR_HOST=""
RADARR_PORT="7878"
EXCLUE_FILENAMES_CONTAINING="PP-SHRUNK"
################################################################################################
# Progress bar function
prog() {
local w=50 p=$1; shift
printf -v dots "%*s" "$(( $p*$w/100 ))" ""; dots=${dots// /#};
printf "\r\e[K|%-*s| %3d %% %s" "$w" "$dots" "$p" "$*";
}
echo -e "++ Radarr Rescan Movie ++\n------------------------------\n\n"
echo "Querying API for complete movie collection - 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'`
echo -e "\nProcessing results:"
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')`
# Simple progress bar so we know how far through the script we are (great for large collections)...
taskpercent=$((i*100/total))
prog "$taskpercent" $MOVIENAME - $ID ...
# 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/command?name=RescanMovie?movieId=$ID
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" \
-X POST -d "{\"name\":\"RescanMovie\",\"movieId\":\"$ID\"}" >> /dev/null
done
prog "$taskpercent" ""
echo -e "\n Finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment