143 lines
4.8 KiB
Bash
Executable File
143 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Configure Radarr and Sonarr quality profiles for 1080p minimum
|
|
# Run on Netcup after services are running
|
|
#
|
|
# Usage: ./configure-quality-profiles.sh
|
|
# Requires: RADARR_API_KEY and SONARR_API_KEY in .env or environment
|
|
|
|
set -euo pipefail
|
|
|
|
# Load .env if available
|
|
[ -f /opt/media-server/.env ] && { set -a; source /opt/media-server/.env; set +a; }
|
|
|
|
RADARR_URL="${RADARR_URL:-http://localhost:7878}"
|
|
SONARR_URL="${SONARR_URL:-http://localhost:8989}"
|
|
|
|
# Fetch API keys from config if not in environment
|
|
if [ -z "${RADARR_API_KEY:-}" ]; then
|
|
RADARR_API_KEY=$(grep -oP '<ApiKey>\K[^<]+' /opt/media-server/config/radarr/config.xml 2>/dev/null || true)
|
|
fi
|
|
if [ -z "${SONARR_API_KEY:-}" ]; then
|
|
SONARR_API_KEY=$(grep -oP '<ApiKey>\K[^<]+' /opt/media-server/config/sonarr/config.xml 2>/dev/null || true)
|
|
fi
|
|
|
|
if [ -z "$RADARR_API_KEY" ] || [ -z "$SONARR_API_KEY" ]; then
|
|
echo "ERROR: Could not find API keys. Set RADARR_API_KEY and SONARR_API_KEY."
|
|
exit 1
|
|
fi
|
|
|
|
echo "=== Configuring Radarr Quality Profiles ==="
|
|
|
|
# Get existing quality profiles from Radarr
|
|
RADARR_PROFILES=$(curl -sf "${RADARR_URL}/api/v3/qualityprofile" \
|
|
-H "X-Api-Key: ${RADARR_API_KEY}")
|
|
|
|
if [ -z "$RADARR_PROFILES" ]; then
|
|
echo "ERROR: Could not fetch Radarr profiles"
|
|
exit 1
|
|
fi
|
|
|
|
# Update each profile: set cutoff and minimum to 1080p qualities
|
|
echo "$RADARR_PROFILES" | jq -c '.[]' | while read -r profile; do
|
|
PROFILE_ID=$(echo "$profile" | jq '.id')
|
|
PROFILE_NAME=$(echo "$profile" | jq -r '.name')
|
|
|
|
# Build updated profile: disable all qualities below 1080p
|
|
UPDATED=$(echo "$profile" | jq '
|
|
.items |= map(
|
|
if .quality then
|
|
# Disable individual qualities below 1080p
|
|
if (.quality.resolution // 0) < 1080 and (.quality.resolution // 0) > 0 then
|
|
.allowed = false
|
|
else
|
|
.
|
|
end
|
|
elif .name then
|
|
# Handle quality groups - disable groups that are sub-1080p
|
|
if (.name | test("480p|720p|SD|DVD"; "i")) then
|
|
.allowed = false |
|
|
.items |= map(.allowed = false)
|
|
else
|
|
.
|
|
end
|
|
else
|
|
.
|
|
end
|
|
) |
|
|
# Set cutoff to Bluray-1080p quality ID (7) or HDTV-1080p (9)
|
|
# This ensures upgrades continue until at least 1080p Bluray
|
|
.upgradeAllowed = true
|
|
')
|
|
|
|
echo " Updating Radarr profile: ${PROFILE_NAME} (ID: ${PROFILE_ID})"
|
|
curl -sf -X PUT "${RADARR_URL}/api/v3/qualityprofile/${PROFILE_ID}" \
|
|
-H "X-Api-Key: ${RADARR_API_KEY}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$UPDATED" > /dev/null
|
|
|
|
echo " Done"
|
|
done
|
|
|
|
echo ""
|
|
echo "=== Configuring Sonarr Quality Profiles ==="
|
|
|
|
# Get existing quality profiles from Sonarr
|
|
SONARR_PROFILES=$(curl -sf "${SONARR_URL}/api/v3/qualityprofile" \
|
|
-H "X-Api-Key: ${SONARR_API_KEY}")
|
|
|
|
if [ -z "$SONARR_PROFILES" ]; then
|
|
echo "ERROR: Could not fetch Sonarr profiles"
|
|
exit 1
|
|
fi
|
|
|
|
echo "$SONARR_PROFILES" | jq -c '.[]' | while read -r profile; do
|
|
PROFILE_ID=$(echo "$profile" | jq '.id')
|
|
PROFILE_NAME=$(echo "$profile" | jq -r '.name')
|
|
|
|
UPDATED=$(echo "$profile" | jq '
|
|
.items |= map(
|
|
if .quality then
|
|
if (.quality.resolution // 0) < 1080 and (.quality.resolution // 0) > 0 then
|
|
.allowed = false
|
|
else
|
|
.
|
|
end
|
|
elif .name then
|
|
if (.name | test("480p|720p|SD|DVD|SDTV"; "i")) then
|
|
.allowed = false |
|
|
.items |= map(.allowed = false)
|
|
else
|
|
.
|
|
end
|
|
else
|
|
.
|
|
end
|
|
) |
|
|
.upgradeAllowed = true
|
|
')
|
|
|
|
echo " Updating Sonarr profile: ${PROFILE_NAME} (ID: ${PROFILE_ID})"
|
|
curl -sf -X PUT "${SONARR_URL}/api/v3/qualityprofile/${PROFILE_ID}" \
|
|
-H "X-Api-Key: ${SONARR_API_KEY}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$UPDATED" > /dev/null
|
|
|
|
echo " Done"
|
|
done
|
|
|
|
echo ""
|
|
echo "=== Configuration Complete ==="
|
|
echo ""
|
|
echo "Quality profiles updated:"
|
|
echo " - All sub-1080p qualities (480p, 720p, SD, DVD) DISABLED"
|
|
echo " - Upgrades enabled to prefer higher quality"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Start Bazarr: docker compose up -d bazarr"
|
|
echo " 2. Open https://subtitles.jefflix.lol"
|
|
echo " 3. Connect Bazarr to Radarr (${RADARR_URL}, key from config.xml)"
|
|
echo " 4. Connect Bazarr to Sonarr (${SONARR_URL}, key from config.xml)"
|
|
echo " 5. Add subtitle providers: OpenSubtitles.com, Subscene, Addic7ed"
|
|
echo " 6. Set languages: English (+ any others you want)"
|
|
echo " 7. Enable 'Auto' mode so Bazarr fetches subs for all existing + new content"
|