Skip to content

Commit a3b8555

Browse files
Merge pull request #337 from natanaelsc/tdarrscan
[Sonarr/Radarr] Added script to send scan request to Tdarr after file download or import event
2 parents b8c324b + db0db3d commit a3b8555

File tree

8 files changed

+195
-0
lines changed

8 files changed

+195
-0
lines changed

radarr/AutoConfig.service

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ];
7777
updateArr=$(curl -s "$arrUrl/api/v3/notification?" -X POST -H "Content-Type: application/json" -H "X-Api-Key: ${arrApiKey}" --data-raw '{"onGrab":false,"onDownload":true,"onUpgrade":true,"onRename":true,"onMovieAdded":false,"onMovieDelete":false,"onMovieFileDelete":false,"onMovieFileDeleteForUpgrade":false,"onHealthIssue":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnDownload":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnMovieAdded":true,"supportsOnMovieDelete":true,"supportsOnMovieFileDelete":true,"supportsOnMovieFileDeleteForUpgrade":true,"supportsOnHealthIssue":true,"supportsOnApplicationUpdate":true,"includeHealthWarnings":false,"name":"Extras.bash","fields":[{"name":"path","value":"/config/extended/Extras.bash"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"https://wiki.servarr.com/radarr/supported#customscript","message":{"message":"Testing will execute the script with the EventType set to Test, ensure your script handles this correctly","type":"warning"},"tags":[]}')
7878
log "Complete"
7979
fi
80+
81+
## Tdarr Scan
82+
if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "TdarrScan.bash" | read; then
83+
log "TdarrScan.bash already added to Radarr custom scripts"
84+
else
85+
log "Adding TdarrScan.bash to Radarr custom scripts"
86+
updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2Fscripts%2FTdarrScan.bash&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}")
87+
updateArr=$(curl -s "$arrUrl/api/v3/notification?" -X POST -H "Content-Type: application/json" -H "X-Api-Key: ${arrApiKey}" --data-raw '{"onGrab":false,"onDownload":true,"onUpgrade":true,"onRename":false,"onMovieAdded":false,"onMovieDelete":false,"onMovieFileDelete":false,"onMovieFileDeleteForUpgrade":true,"onHealthIssue":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnDownload":true,"supportsOnUpgrade":true,"supportsOnRename":false,"supportsOnMovieAdded":true,"supportsOnMovieDelete":false,"supportsOnMovieFileDelete":false,"supportsOnMovieFileDeleteForUpgrade":true,"supportsOnHealthIssue":false,"supportsOnApplicationUpdate":false,"includeHealthWarnings":false,"name":"TdarrScan.bash","fields":[{"name":"path","value":"/config/extended/TdarrScan.bash"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"https://wiki.servarr.com/radarr/supported#customscript","message":{"message":"Testing will execute the script with the EventType set to Test, ensure your script handles this correctly","type":"warning"},"tags":[]}')
88+
log "Complete"
89+
fi
8090
fi
8191

8292
if [ "$configureCustomFormats" == "true" ] || [ -z "$configureCustomFormats" ]; then

radarr/TdarrScan.bash

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
scriptVersion="1.0"
3+
scriptName="TdarrScan"
4+
5+
#### Import Settings
6+
source /config/extended.conf
7+
8+
log () {
9+
m_time=`date "+%F %T"`
10+
echo $m_time" :: $scriptName :: $scriptVersion :: "$1
11+
}
12+
13+
notfidedBy="Radarr"
14+
arrEventType="$radarr_eventtype"
15+
contentPath="$(dirname "$radarr_moviefile_path")"
16+
file="$radarr_moviefile_path"
17+
18+
# Clean up old logs greater than 1MB
19+
if [ -f "/config/logs/$scriptName.txt" ]; then
20+
find /config/logs -type f -name "$scriptName.txt" -size +1024k -delete
21+
fi
22+
23+
# Create log file if it doesn't exist
24+
if [ ! -f "/config/logs/$scriptName.txt" ]; then
25+
touch "/config/logs/$scriptName.txt"
26+
chmod 777 "/config/logs/$scriptName.txt"
27+
fi
28+
exec &> >(tee -a "/config/logs/$scriptName.txt")
29+
30+
if [ -z "$tdarrUrl" ]; then
31+
log "$notfidedBy :: tdarrUrl is not set, skipping..."
32+
exit
33+
fi
34+
35+
# Validate connection
36+
TdarrValidateConnection () {
37+
tdarrVersion=$(curl -m 5 -s "$tdarrUrl/api/v2/status" | jq -r '.version')
38+
if [ "$tdarrVersion" == "" ]; then
39+
log "ERROR :: Cannot communicate with Tdarr"
40+
log "ERROR :: Please check your tdarrUrl"
41+
log "ERROR :: Configured tdarrUrl \"$tdarrUrl\""
42+
log "ERROR :: Exiting..."
43+
exit 1
44+
else
45+
log "Tdarr Connection Established, version: $tdarrVersion"
46+
fi
47+
}
48+
49+
# Test connection
50+
if [ "$arrEventType" == "Test" ]; then
51+
TdarrValidateConnection
52+
log "$notfidedBy :: Tested Successfully"
53+
exit 0
54+
fi
55+
56+
TdarrValidateConnection
57+
58+
payload="{ \"data\": { \"folderPath\": \"$contentPath\" }}"
59+
60+
# Check if path exists in Tdarr
61+
if [ $(curl -s -X POST "$tdarrUrl/api/v2/verify-folder-exists" -H "Content-Type: application/json" -d "$payload" 2>/dev/null) == "false" ]; then
62+
log "$notfidedBy :: ERROR: Path \"$contentPath\" does not exist in Tdarr"
63+
exit 1
64+
fi
65+
66+
payload="{ \"data\": { \"scanConfig\": {\"dbID\": \"$tdarrDbID\", \"arrayOrPath\": [\"$file\"], \"mode\": \"scanFolderWatcher\" }}}"
67+
68+
# Send scan request to Tdarr
69+
if [[ -n "$arrEventType" && "$arrEventType" != "Test" ]]; then
70+
curl -s -X POST "$tdarrUrl/api/v2/scan-files" -H "Content-Type: application/json" -d "$payload" >/dev/null 2>&1
71+
if [ $? -eq 0 ]; then
72+
log "$notfidedBy :: Scan request sent to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
73+
else
74+
log "$notfidedBy :: ERROR: Failed to send scan request to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
75+
fi
76+
fi
77+
78+
exit

radarr/extended.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ recyclarrConfig="/config/extended/recyclarr.yaml" # Change to a custom yaml file
3636
##### PLEX NOTIFY SCRIPT
3737
plexUrl="" # ONLY used if PlexNotify.bash is used, example: http://x.x.x.x:32400
3838
plexToken="" # ONLY used if PlexNotify.bash is used
39+
40+
##### TDARR SCAN SCRIPT
41+
tdarrUrl="" # ONLY used if TdarrScan.bash is used, example: http://x.x.x.x:8265
42+
tdarrDbID="" # ONLY used if TdarrScan.bash is used. The ID of the library you want to scan in Tdarr

radarr/setup.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ echo "Download Extras script..."
9494
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/Extras.bash -o /config/extended/Extras.bash
9595
echo "Done"
9696

97+
echo "Download TdarrScan script..."
98+
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/TdarrScan.bash -o /config/extended/TdarrScan.bash
99+
echo "Done"
100+
97101
if [ ! -f /config/extended/sma.ini ]; then
98102
echo "Download SMA config..."
99103
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/sma.ini -o /config/extended/sma.ini

sonarr/AutoConfig.service

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ];
105105
updateArr=$(curl -s "$arrUrl/api/v3/notification?" -X POST -H "Content-Type: application/json" -H "X-Api-Key: ${arrApiKey}" --data-raw '{"onGrab":false,"onDownload":true,"onUpgrade":true,"onRename":true,"onSeriesDelete":false,"onEpisodeFileDelete":false,"onEpisodeFileDeleteForUpgrade":false,"onHealthIssue":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnDownload":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnSeriesDelete":false,"supportsOnEpisodeFileDelete":true,"supportsOnEpisodeFileDeleteForUpgrade":true,"supportsOnHealthIssue":true,"supportsOnApplicationUpdate":true,"includeHealthWarnings":false,"name":"Extras.bash","fields":[{"name":"path","value":"/config/extended/Extras.bash"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"https://wiki.servarr.com/sonarr/supported#customscript","message":{"message":"Testing will execute the script with the EventType set to Test, ensure your script handles this correctly","type":"warning"},"tags":[]}')
106106
log "Complete"
107107
fi
108+
109+
## Tdarr Scan
110+
if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "TdarrScan.bash" | read; then
111+
log "TdarrScan.bash already added to Sonarr custom scripts"
112+
else
113+
log "Adding TdarrScan.bash to Sonarr custom scripts"
114+
# Send a command to check file path, to prevent error with adding...
115+
updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2Fscripts%2FTdarrScan.bash&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}")
116+
117+
# Add TdarrScan.bash
118+
updateArr=$(curl -s "$arrUrl/api/v3/notification?" -X POST -H "Content-Type: application/json" -H "X-Api-Key: ${arrApiKey}" --data-raw '{"onGrab":false,"onDownload":true,"onUpgrade":true,"onRename":false,"onSeriesDelete":false,"onEpisodeFileDelete":false,"onEpisodeFileDeleteForUpgrade":false,"onHealthIssue":false,"onApplicationUpdate":false,"supportsOnGrab":false,"supportsOnDownload":true,"supportsOnUpgrade":true,"supportsOnRename":false,"supportsOnSeriesDelete":false,"supportsOnEpisodeFileDelete":false,"supportsOnEpisodeFileDeleteForUpgrade":true,"supportsOnHealthIssue":false,"supportsOnApplicationUpdate":false,"includeHealthWarnings":false,"name":"TdarrScan.bash","fields":[{"name":"path","value":"/config/extended/TdarrScan.bash"},{"name":"arguments"}],"implementationName":"Custom Script","implementation":"CustomScript","configContract":"CustomScriptSettings","infoLink":"https://wiki.servarr.com/sonarr/supported#customscript","message":{"message":"Testing will execute the script with the EventType set to Test, ensure your script handles this correctly","type":"warning"},"tags":[]}')
119+
log "Complete"
120+
fi
108121
fi
109122

110123

sonarr/TdarrScan.bash

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
scriptVersion="1.0"
3+
scriptName="TdarrScan"
4+
5+
#### Import Settings
6+
source /config/extended.conf
7+
8+
log () {
9+
m_time=`date "+%F %T"`
10+
echo $m_time" :: $scriptName :: $scriptVersion :: "$1
11+
}
12+
13+
notfidedBy="Sonarr"
14+
arrEventType="$sonarr_eventtype"
15+
contentPath="$(dirname "$sonarr_episodefile_path")"
16+
file="$sonarr_episodefile_path"
17+
18+
# Clean up old logs greater than 1MB
19+
if [ -f "/config/logs/$scriptName.txt" ]; then
20+
find /config/logs -type f -name "$scriptName.txt" -size +1024k -delete
21+
fi
22+
23+
# Create log file if it doesn't exist
24+
if [ ! -f "/config/logs/$scriptName.txt" ]; then
25+
touch "/config/logs/$scriptName.txt"
26+
chmod 777 "/config/logs/$scriptName.txt"
27+
fi
28+
exec &> >(tee -a "/config/logs/$scriptName.txt")
29+
30+
if [ -z "$tdarrUrl" ]; then
31+
log "$notfidedBy :: tdarrUrl is not set, skipping..."
32+
exit
33+
fi
34+
35+
# Validate connection
36+
TdarrValidateConnection () {
37+
tdarrVersion=$(curl -m 5 -s "$tdarrUrl/api/v2/status" | jq -r '.version')
38+
if [ "$tdarrVersion" == "" ]; then
39+
log "ERROR :: Cannot communicate with Tdarr"
40+
log "ERROR :: Please check your tdarrUrl"
41+
log "ERROR :: Configured tdarrUrl \"$tdarrUrl\""
42+
log "ERROR :: Exiting..."
43+
exit 1
44+
else
45+
log "Tdarr Connection Established, version: $tdarrVersion"
46+
fi
47+
}
48+
49+
# Test connection
50+
if [ "$arrEventType" == "Test" ]; then
51+
TdarrValidateConnection
52+
log "$notfidedBy :: Tested Successfully"
53+
exit 0
54+
fi
55+
56+
TdarrValidateConnection
57+
58+
payload="{ \"data\": { \"folderPath\": \"$contentPath\" }}"
59+
60+
# Check if path exists in Tdarr
61+
if [ $(curl -s -X POST "$tdarrUrl/api/v2/verify-folder-exists" -H "Content-Type: application/json" -d "$payload" 2>/dev/null) == "false" ]; then
62+
log "$notfidedBy :: ERROR: Path \"$contentPath\" does not exist in Tdarr"
63+
exit 1
64+
fi
65+
66+
payload="{ \"data\": { \"scanConfig\": {\"dbID\": \"$tdarrDbID\", \"arrayOrPath\": [\"$file\"], \"mode\": \"scanFolderWatcher\" }}}"
67+
68+
# Send scan request to Tdarr
69+
if [[ -n "$arrEventType" && "$arrEventType" != "Test" ]]; then
70+
curl -s -X POST "$tdarrUrl/api/v2/scan-files" -H "Content-Type: application/json" -d "$payload" >/dev/null 2>&1
71+
if [ $? -eq 0 ]; then
72+
log "$notfidedBy :: Scan request sent to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
73+
else
74+
log "$notfidedBy :: ERROR: Failed to send scan request to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
75+
fi
76+
fi
77+
78+
exit

sonarr/extended.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ recyclarrConfig="/config/extended/recyclarr.yaml" # Change to a custom yaml file
4141
##### PLEX NOTIFY SCRIPT
4242
plexUrl="" # ONLY used if PlexNotify.bash is used, example: http://x.x.x.x:32400
4343
plexToken="" # ONLY used if PlexNotify.bash is used
44+
45+
##### TDARR SCAN SCRIPT
46+
tdarrUrl="" # ONLY used if TdarrScan.bash is used, example: http://x.x.x.x:8265
47+
tdarrDbID="" # ONLY used if TdarrScan.bash is used. The ID of the library you want to scan in Tdarr

sonarr/setup.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ echo "Download Extras script..."
9595
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/Extras.bash -o /config/extended/Extras.bash
9696
echo "Done"
9797

98+
echo "Download TdarrScan script..."
99+
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/TdarrScan.bash -o /config/extended/TdarrScan.bash
100+
echo "Done"
101+
98102
if [ ! -f /config/extended/sma.ini ]; then
99103
echo "Download SMA config..."
100104
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/sma.ini -o /config/extended/sma.ini

0 commit comments

Comments
 (0)