Created
September 4, 2025 09:35
-
-
Save evenwebb/1fe6e3f972d8da5430199ea4b2ab6f29 to your computer and use it in GitHub Desktop.
This script automates Radarr quality profile management by ensuring movies from the current year are assigned to a dedicated profile while reverting previous year’s titles back to a default profile.
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 | |
| RADARR_URL="http://192.168.1.1:7878" | |
| API_KEY="234234234234234234234234234234234234234" | |
| CURRENT_YEAR_PROFILE_ID=9 | |
| DEFAULT_PROFILE_ID=2 | |
| DRY_RUN=0 # 1 = dry run, 0 = live | |
| THIS_YEAR=$(date +"%Y") | |
| PREV_YEAR=$((THIS_YEAR - 1)) | |
| echo "--------------------------------------------" | |
| echo "Radarr Quality Profile Updater" | |
| echo "Efficiently processing only needed movies" | |
| echo "--------------------------------------------" | |
| # Efficiently select only movies needing a change: | |
| # - Current year movies NOT set to CURRENT_YEAR_PROFILE_ID | |
| # - Previous year movies still set to CURRENT_YEAR_PROFILE_ID | |
| MOVIES=$(curl -s -H "X-Api-Key: $API_KEY" "$RADARR_URL/api/v3/movie" | \ | |
| jq --arg thisyear "$THIS_YEAR" \ | |
| --arg prevyear "$PREV_YEAR" \ | |
| --argjson curprof "$CURRENT_YEAR_PROFILE_ID" \ | |
| '[.[] | | |
| select( | |
| (.year == ($thisyear|tonumber) and .qualityProfileId != $curprof) or | |
| (.year == ($prevyear|tonumber) and .qualityProfileId == $curprof) | |
| ) | |
| ]' | |
| ) | |
| TOTAL=$(echo "$MOVIES" | jq 'length') | |
| echo "Found $TOTAL movies that need a quality profile update..." | |
| if [[ "$TOTAL" -eq 0 ]]; then | |
| echo "No movies need updating. Exiting." | |
| exit 0 | |
| fi | |
| COUNT=0 | |
| CHANGED=0 | |
| REVERTED=0 | |
| progress_bar() { | |
| local PROGRESS=$1 | |
| local TOTAL=$2 | |
| local WIDTH=40 | |
| local FILLED=$((PROGRESS * WIDTH / TOTAL)) | |
| local EMPTY=$((WIDTH - FILLED)) | |
| printf "\r[" | |
| printf "%0.s#" $(seq 1 $FILLED) | |
| printf "%0.s-" $(seq 1 $EMPTY) | |
| printf "] %d/%d" "$PROGRESS" "$TOTAL" | |
| } | |
| echo "" | |
| echo "Processing movies..." | |
| echo "" | |
| # Use a temp file to store movie lines for safe counting and reading | |
| TMP_FILE=$(mktemp) | |
| echo "$MOVIES" | jq -c '.[]' > "$TMP_FILE" | |
| while read -r MOVIE; do | |
| COUNT=$((COUNT + 1)) | |
| MOVIE_ID=$(echo "$MOVIE" | jq '.id') | |
| MOVIE_TITLE=$(echo "$MOVIE" | jq -r '.title') | |
| MOVIE_YEAR=$(echo "$MOVIE" | jq '.year') | |
| PROFILE_ID=$(echo "$MOVIE" | jq '.qualityProfileId') | |
| # Show progress bar | |
| progress_bar $COUNT $TOTAL | |
| # Current year logic: set to CURRENT_YEAR_PROFILE_ID if not already | |
| if [[ "$MOVIE_YEAR" -eq "$THIS_YEAR" && "$PROFILE_ID" -ne "$CURRENT_YEAR_PROFILE_ID" ]]; then | |
| if [[ "$DRY_RUN" -eq 0 ]]; then | |
| FULL_MOVIE=$(curl -s -H "X-Api-Key: $API_KEY" "$RADARR_URL/api/v3/movie/$MOVIE_ID") | |
| UPDATED_MOVIE=$(echo "$FULL_MOVIE" | jq --argjson pid "$CURRENT_YEAR_PROFILE_ID" '.qualityProfileId = $pid') | |
| curl -s -X PUT -H "X-Api-Key: $API_KEY" -H "Content-Type: application/json" \ | |
| -d "$UPDATED_MOVIE" "$RADARR_URL/api/v3/movie/$MOVIE_ID" >/dev/null | |
| fi | |
| CHANGED=$((CHANGED + 1)) | |
| fi | |
| # Previous year logic: revert to DEFAULT_PROFILE_ID if still set to CURRENT_YEAR_PROFILE_ID | |
| if [[ "$MOVIE_YEAR" -eq "$PREV_YEAR" && "$PROFILE_ID" -eq "$CURRENT_YEAR_PROFILE_ID" ]]; then | |
| if [[ "$DRY_RUN" -eq 0 ]]; then | |
| FULL_MOVIE=$(curl -s -H "X-Api-Key: $API_KEY" "$RADARR_URL/api/v3/movie/$MOVIE_ID") | |
| UPDATED_MOVIE=$(echo "$FULL_MOVIE" | jq --argjson pid "$DEFAULT_PROFILE_ID" '.qualityProfileId = $pid') | |
| curl -s -X PUT -H "X-Api-Key: $API_KEY" -H "Content-Type: application/json" \ | |
| -d "$UPDATED_MOVIE" "$RADARR_URL/api/v3/movie/$MOVIE_ID" >/dev/null | |
| fi | |
| REVERTED=$((REVERTED + 1)) | |
| fi | |
| done < "$TMP_FILE" | |
| # Move to new line after progress bar | |
| echo "" | |
| echo "--------------------------------------------" | |
| echo "Radarr Quality Profile Updater complete!" | |
| echo "Movies updated to current year profile: $CHANGED" | |
| echo "Movies reverted to default profile: $REVERTED" | |
| echo "Dry-run mode: $DRY_RUN" | |
| echo "--------------------------------------------" | |
| rm "$TMP_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment