2023-07-08 19:32:34 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-07-20 13:15:41 +02:00
|
|
|
scriptVersion="1.7"
|
2023-07-12 13:20:31 +02:00
|
|
|
scriptName="InvalidSeriesAutoCleaner"
|
|
|
|
|
2023-07-20 13:15:41 +02:00
|
|
|
#### Import Settings
|
|
|
|
source /config/extended.conf
|
|
|
|
#### Import Functions
|
|
|
|
source /config/extended/functions
|
|
|
|
#### Create Log File
|
2023-07-19 20:09:59 +02:00
|
|
|
logfileSetup
|
2023-07-20 13:15:41 +02:00
|
|
|
#### Check Arr App
|
|
|
|
getArrAppInfo
|
|
|
|
verifyApiAccess
|
2023-07-19 20:09:59 +02:00
|
|
|
|
2023-07-15 22:10:04 +02:00
|
|
|
verifyConfig () {
|
|
|
|
|
|
|
|
if [ "$enableInvalidSeriesAutoCleaner" != "true" ]; then
|
2023-07-12 13:20:31 +02:00
|
|
|
log "Script is not enabled, enable by setting enableInvalidSeriesAutoCleaner to \"true\" by modifying the \"/config/extended.conf\" config file..."
|
|
|
|
log "Sleeping (infinity)"
|
|
|
|
sleep infinity
|
2023-07-15 22:10:04 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$invalidSeriesAutoCleanerScriptInterval" ]; then
|
|
|
|
invalidSeriesAutoCleanerScriptInterval="1h"
|
|
|
|
fi
|
|
|
|
}
|
2023-07-08 19:32:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
InvalidSeriesAutoCleanerProcess () {
|
|
|
|
|
|
|
|
# Get invalid series tvdb id's
|
|
|
|
seriesTvdbId="$(curl -s --header "X-Api-Key:"$arrApiKey --request GET "$arrUrl/api/v3/health" | jq -r '.[] | select(.source=="RemovedSeriesCheck") | select(.type=="error")' | grep "message" | grep -o '[[:digit:]]*')"
|
|
|
|
|
|
|
|
if [ -z "$seriesTvdbId" ]; then
|
|
|
|
log "No invalid series (tvdbid) reported by Sonarr health check, skipping..."
|
2023-07-08 19:36:40 +02:00
|
|
|
return
|
2023-07-08 19:32:34 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Process each invalid series tvdb id
|
|
|
|
for tvdbId in $(echo $seriesTvdbId); do
|
|
|
|
seriesData="$(curl -s --header "X-Api-Key:"$arrApiKey --request GET "$arrUrl/api/v3/series" | jq -r ".[] | select(.tvdbId==$tvdbId)")"
|
|
|
|
seriesId="$(echo "$seriesData" | jq -r .id)"
|
|
|
|
seriesTitle="$(echo "$seriesData" | jq -r .title)"
|
|
|
|
seriesPath="$(echo "$seriesData" | jq -r .path)"
|
|
|
|
|
|
|
|
log "$seriesId :: $seriesTitle :: $seriesPath :: Removing and deleting invalid Series (tvdbId: $tvdbId) based on Sonarr Health Check error..."
|
|
|
|
|
|
|
|
# Send command to Sonarr to delete series and files
|
|
|
|
arrCommand=$(curl -s --header "X-Api-Key:"$arrApiKey --request DELETE "$arrUrl/api/v3/series/$seriesId?deleteFiles=true")
|
|
|
|
|
|
|
|
|
|
|
|
# trigger a plex scan to rmeove the deleted series
|
|
|
|
folderToScan="$(dirname "$seriesPath")"
|
|
|
|
log "Using PlexNotify.bash to update Plex.... ($folderToScan)"
|
2023-07-08 19:37:22 +02:00
|
|
|
bash /config/extended/PlexNotify.bash "$folderToScan" "true"
|
2023-07-08 19:32:34 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
for (( ; ; )); do
|
|
|
|
let i++
|
2023-07-15 22:10:04 +02:00
|
|
|
logfileSetup
|
|
|
|
log "Script starting..."
|
|
|
|
verifyConfig
|
|
|
|
getArrAppInfo
|
|
|
|
verifyApiAccess
|
2023-07-08 19:32:34 +02:00
|
|
|
InvalidSeriesAutoCleanerProcess
|
2023-07-15 22:17:08 +02:00
|
|
|
log "Script sleeping for $invalidSeriesAutoCleanerScriptInterval..."
|
2023-07-15 22:10:04 +02:00
|
|
|
sleep $invalidSeriesAutoCleanerScriptInterval
|
2023-07-08 19:32:34 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
exit
|