From 53d37a443b128dd99f8790db8513dbf484033952 Mon Sep 17 00:00:00 2001 From: Thomas Gander Date: Sun, 1 Mar 2026 23:08:29 -0700 Subject: [PATCH] Initial commit --- postprocess.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 postprocess.sh diff --git a/postprocess.sh b/postprocess.sh new file mode 100644 index 0000000..c1fb024 --- /dev/null +++ b/postprocess.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# This script requires that sabnzbd will reject duplicate nzbs allowing sonarr to blocklist the request. + +# ===== CONFIG ===== +SONARR_URL="http://localhost:8989" +API_KEY="YOUR_API_KEY" +# ================== + +log() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >&2 +} + +# Only act on Import/Upgrade +if [ "$sonarr_eventtype" != "Download" ]; then + log "Ignoring event type: $sonarr_eventtype" + exit 0 +fi + +# Provided from sonarr environment when job runs +SERIES_ID="$sonarr_series_id" +EPISODEFILE_ID="$sonarr_episodefile_id" +EPISODE_IDS="$sonarr_episodefile_episodeids" + +log "Episode File ID: $EPISODEFILE_ID" +log "Episode IDs: $EPISODE_IDS" + +if [ -z "$EPISODEFILE_ID" ]; then + log "No episodefile ID supplied." + exit 1 +fi + +if [ -z "$EPISODE_IDS" ]; then + log "No episode IDs supplied." + exit 1 +fi + +log "Processing EpisodeFile ID: $EPISODEFILE_ID" +log "Processing EpisodeIDs: $EPISODE_IDS" + +# Get episodefile details +EPISODEFILE=$(curl -s -H "X-Api-Key: $API_KEY" \ + "$SONARR_URL/api/v3/episodefile/$EPISODEFILE_ID") +SCORE=$(echo "$EPISODEFILE" | jq '.customFormatScore') + +log "Custom Format Score: $SCORE" + +if [ "$SCORE" -lt 0 ]; then + log "Score below zero — rejecting release." + + # Delete episodefile + curl -s -X DELETE \ + -H "X-Api-Key: $API_KEY" \ + "$SONARR_URL/api/v3/episodefile/$EPISODEFILE_ID?deleteFiles=true" \ + > /dev/null + + log "Episode file deleted." + + # Trigger re-search + curl -s -X POST "$SONARR_URL/api/v3/command" \ + -H "X-Api-Key: $API_KEY" \ + -H "Content-Type: application/json" \ + -d "{ + \"name\": \"EpisodeSearch\", + \"episodeIds\": [$EPISODE_IDS], + \"ignoreDeleted\": true, + \"searchForUpgrade\": true + }" > /dev/null + + log "Re-search triggered." + + exit 1 +fi + +log "Score acceptable." +exit 0