77 lines
1.8 KiB
Bash
77 lines
1.8 KiB
Bash
#!/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
|