-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRadarr-Invalid-Movie-Auto-Cleaner.bash
More file actions
110 lines (89 loc) · 3.45 KB
/
Radarr-Invalid-Movie-Auto-Cleaner.bash
File metadata and controls
110 lines (89 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
scriptVersion="1.2"
scriptName="Radarr-Invalid-Movie-Auto-Cleaner"
dockerLogPath="/config/logs"
settings () {
log "Import Script $1 Settings..."
source "$1"
arrUrl="$radarrUrl"
arrApiKey="$radarrApiKey"
}
logfileSetup () {
logFileName="$scriptName-$(date +"%Y_%m_%d_%I_%M_%p").txt"
if [ ! -d "$dockerLogPath" ]; then
mkdir -p "$dockerLogPath"
chown ${PUID:-1000}:${PGID:-1000} "$dockerLogPath"
chmod 777 "$dockerLogPath"
fi
if find "$dockerLogPath" -type f -iname "$scriptName-*.txt" | read; then
# Keep only the last 5 log files for 6 active log files at any given time...
rm -f $(ls -1t $dockerLogPath/$scriptName-* | tail -n +5)
# delete log files older than 5 days
find "$dockerLogPath" -type f -iname "$scriptName-*.txt" -mtime +5 -delete
fi
if [ ! -f "$dockerLogPath/$logFileName" ]; then
echo "" > "$dockerLogPath/$logFileName"
chown ${PUID:-1000}:${PGID:-1000} "$dockerLogPath/$logFileName"
chmod 666 "$dockerLogPath/$logFileName"
fi
}
log () {
m_time=`date "+%F %T"`
echo $m_time" :: $scriptName (v$scriptVersion) :: "$1
echo $m_time" :: $scriptName (v$scriptVersion) :: "$1 >> "$dockerLogPath/$logFileName"
}
verifyConfig () {
if [ "$enableInvalidMoviesAutoCleaner" != "true" ]; then
log "Script is not enabled, enable by setting enableInvalidMoviesAutoCleaner to \"true\" by modifying the \"/config/extended.conf\" config file..."
log "Sleeping (infinity)"
sleep infinity
fi
}
InvalidMovieAutoCleanerProcess () {
# Get invalid series tmdbid id's
movieTmdbid="$(curl -s --header "X-Api-Key:"$arrApiKey --request GET "$arrUrl/api/v3/health" | jq -r '.[] | select(.source=="RemovedMovieCheck") | select(.type=="error")' | grep -o 'tmdbid [0-9]*' | grep -o '[[:digit:]]*')"
if [ -z "$movieTmdbid" ]; then
log "No invalid movies (tmdbid) reported by Radarr health check, skipping..."
return
fi
# Process each invalid series tmdb id
moviesData="$(curl -s --header "X-Api-Key:"$arrApiKey --request GET "$arrUrl/api/v3/movie")"
for tmdbid in $(echo $movieTmdbid); do
movieData="$(echo "$moviesData" | jq -r ".[] | select(.tmdbId==$tmdbid)")"
movieId="$(echo "$movieData" | jq -r .id)"
movieTitle="$(echo "$movieData" | jq -r .title)"
moviePath="$(echo "$movieData" | jq -r .path)"
log "$movieId :: $movieTitle :: $moviePath :: Removing and deleting invalid movie (tmdbid: $tmdbid) based on Radarr 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/movie/$movieId?deleteFiles=true")
done
}
for (( ; ; )); do
let i++
logfileSetup
log "Starting..."
confFiles=$(find /config -mindepth 1 -type f -name "*.conf")
confFileCount=$(echo "$confFiles" | wc -l)
if [ -z "$confFiles" ]; then
log "ERROR :: No config files found, exiting..."
exit
fi
for f in $confFiles; do
count=$(($count+1))
log "Processing \"$f\" config file"
settings "$f"
verifyConfig
if [ ! -z "$radarrUrl" ]; then
if [ ! -z "$radarrApiKey" ]; then
InvalidMovieAutoCleanerProcess
else
log "ERROR :: Skipping Radarr, missing API Key..."
fi
else
log "ERROR :: Skipping Radarr, missing URL..."
fi
done
log "Script sleeping for $invalidMoviesAutoCleanerScriptInterval..."
sleep $invalidMoviesAutoCleanerScriptInterval
done
exit