feat: add tdarr scan

This commit is contained in:
Natanael Silva
2024-12-09 21:51:35 -03:00
parent f7c59f8519
commit db0db3dda6
8 changed files with 195 additions and 0 deletions

View File

@@ -77,6 +77,16 @@ if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ];
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":[]}')
log "Complete"
fi
## Tdarr Scan
if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "TdarrScan.bash" | read; then
log "TdarrScan.bash already added to Radarr custom scripts"
else
log "Adding TdarrScan.bash to Radarr custom scripts"
updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2Fscripts%2FTdarrScan.bash&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}")
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":[]}')
log "Complete"
fi
fi
if [ "$configureCustomFormats" == "true" ] || [ -z "$configureCustomFormats" ]; then

78
radarr/TdarrScan.bash Normal file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
scriptVersion="1.0"
scriptName="TdarrScan"
#### Import Settings
source /config/extended.conf
log () {
m_time=`date "+%F %T"`
echo $m_time" :: $scriptName :: $scriptVersion :: "$1
}
notfidedBy="Radarr"
arrEventType="$radarr_eventtype"
contentPath="$(dirname "$radarr_moviefile_path")"
file="$radarr_moviefile_path"
# Clean up old logs greater than 1MB
if [ -f "/config/logs/$scriptName.txt" ]; then
find /config/logs -type f -name "$scriptName.txt" -size +1024k -delete
fi
# Create log file if it doesn't exist
if [ ! -f "/config/logs/$scriptName.txt" ]; then
touch "/config/logs/$scriptName.txt"
chmod 777 "/config/logs/$scriptName.txt"
fi
exec &> >(tee -a "/config/logs/$scriptName.txt")
if [ -z "$tdarrUrl" ]; then
log "$notfidedBy :: tdarrUrl is not set, skipping..."
exit
fi
# Validate connection
TdarrValidateConnection () {
tdarrVersion=$(curl -m 5 -s "$tdarrUrl/api/v2/status" | jq -r '.version')
if [ "$tdarrVersion" == "" ]; then
log "ERROR :: Cannot communicate with Tdarr"
log "ERROR :: Please check your tdarrUrl"
log "ERROR :: Configured tdarrUrl \"$tdarrUrl\""
log "ERROR :: Exiting..."
exit 1
else
log "Tdarr Connection Established, version: $tdarrVersion"
fi
}
# Test connection
if [ "$arrEventType" == "Test" ]; then
TdarrValidateConnection
log "$notfidedBy :: Tested Successfully"
exit 0
fi
TdarrValidateConnection
payload="{ \"data\": { \"folderPath\": \"$contentPath\" }}"
# Check if path exists in Tdarr
if [ $(curl -s -X POST "$tdarrUrl/api/v2/verify-folder-exists" -H "Content-Type: application/json" -d "$payload" 2>/dev/null) == "false" ]; then
log "$notfidedBy :: ERROR: Path \"$contentPath\" does not exist in Tdarr"
exit 1
fi
payload="{ \"data\": { \"scanConfig\": {\"dbID\": \"$tdarrDbID\", \"arrayOrPath\": [\"$file\"], \"mode\": \"scanFolderWatcher\" }}}"
# Send scan request to Tdarr
if [[ -n "$arrEventType" && "$arrEventType" != "Test" ]]; then
curl -s -X POST "$tdarrUrl/api/v2/scan-files" -H "Content-Type: application/json" -d "$payload" >/dev/null 2>&1
if [ $? -eq 0 ]; then
log "$notfidedBy :: Scan request sent to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
else
log "$notfidedBy :: ERROR: Failed to send scan request to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
fi
fi
exit

View File

@@ -36,3 +36,7 @@ recyclarrConfig="/config/extended/recyclarr.yaml" # Change to a custom yaml file
##### PLEX NOTIFY SCRIPT
plexUrl="" # ONLY used if PlexNotify.bash is used, example: http://x.x.x.x:32400
plexToken="" # ONLY used if PlexNotify.bash is used
##### TDARR SCAN SCRIPT
tdarrUrl="" # ONLY used if TdarrScan.bash is used, example: http://x.x.x.x:8265
tdarrDbID="" # ONLY used if TdarrScan.bash is used. The ID of the library you want to scan in Tdarr

View File

@@ -94,6 +94,10 @@ echo "Download Extras script..."
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/Extras.bash -o /config/extended/Extras.bash
echo "Done"
echo "Download TdarrScan script..."
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/TdarrScan.bash -o /config/extended/TdarrScan.bash
echo "Done"
if [ ! -f /config/extended/sma.ini ]; then
echo "Download SMA config..."
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/sma.ini -o /config/extended/sma.ini

View File

@@ -105,6 +105,19 @@ if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ];
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":[]}')
log "Complete"
fi
## Tdarr Scan
if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "TdarrScan.bash" | read; then
log "TdarrScan.bash already added to Sonarr custom scripts"
else
log "Adding TdarrScan.bash to Sonarr custom scripts"
# Send a command to check file path, to prevent error with adding...
updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2Fscripts%2FTdarrScan.bash&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}")
# Add TdarrScan.bash
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":[]}')
log "Complete"
fi
fi

78
sonarr/TdarrScan.bash Normal file
View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
scriptVersion="1.0"
scriptName="TdarrScan"
#### Import Settings
source /config/extended.conf
log () {
m_time=`date "+%F %T"`
echo $m_time" :: $scriptName :: $scriptVersion :: "$1
}
notfidedBy="Sonarr"
arrEventType="$sonarr_eventtype"
contentPath="$(dirname "$sonarr_episodefile_path")"
file="$sonarr_episodefile_path"
# Clean up old logs greater than 1MB
if [ -f "/config/logs/$scriptName.txt" ]; then
find /config/logs -type f -name "$scriptName.txt" -size +1024k -delete
fi
# Create log file if it doesn't exist
if [ ! -f "/config/logs/$scriptName.txt" ]; then
touch "/config/logs/$scriptName.txt"
chmod 777 "/config/logs/$scriptName.txt"
fi
exec &> >(tee -a "/config/logs/$scriptName.txt")
if [ -z "$tdarrUrl" ]; then
log "$notfidedBy :: tdarrUrl is not set, skipping..."
exit
fi
# Validate connection
TdarrValidateConnection () {
tdarrVersion=$(curl -m 5 -s "$tdarrUrl/api/v2/status" | jq -r '.version')
if [ "$tdarrVersion" == "" ]; then
log "ERROR :: Cannot communicate with Tdarr"
log "ERROR :: Please check your tdarrUrl"
log "ERROR :: Configured tdarrUrl \"$tdarrUrl\""
log "ERROR :: Exiting..."
exit 1
else
log "Tdarr Connection Established, version: $tdarrVersion"
fi
}
# Test connection
if [ "$arrEventType" == "Test" ]; then
TdarrValidateConnection
log "$notfidedBy :: Tested Successfully"
exit 0
fi
TdarrValidateConnection
payload="{ \"data\": { \"folderPath\": \"$contentPath\" }}"
# Check if path exists in Tdarr
if [ $(curl -s -X POST "$tdarrUrl/api/v2/verify-folder-exists" -H "Content-Type: application/json" -d "$payload" 2>/dev/null) == "false" ]; then
log "$notfidedBy :: ERROR: Path \"$contentPath\" does not exist in Tdarr"
exit 1
fi
payload="{ \"data\": { \"scanConfig\": {\"dbID\": \"$tdarrDbID\", \"arrayOrPath\": [\"$file\"], \"mode\": \"scanFolderWatcher\" }}}"
# Send scan request to Tdarr
if [[ -n "$arrEventType" && "$arrEventType" != "Test" ]]; then
curl -s -X POST "$tdarrUrl/api/v2/scan-files" -H "Content-Type: application/json" -d "$payload" >/dev/null 2>&1
if [ $? -eq 0 ]; then
log "$notfidedBy :: Scan request sent to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
else
log "$notfidedBy :: ERROR: Failed to send scan request to Tdarr for \"$contentPath\" with dbID \"$tdarrDbID\""
fi
fi
exit

View File

@@ -41,3 +41,7 @@ recyclarrConfig="/config/extended/recyclarr.yaml" # Change to a custom yaml file
##### PLEX NOTIFY SCRIPT
plexUrl="" # ONLY used if PlexNotify.bash is used, example: http://x.x.x.x:32400
plexToken="" # ONLY used if PlexNotify.bash is used
##### TDARR SCAN SCRIPT
tdarrUrl="" # ONLY used if TdarrScan.bash is used, example: http://x.x.x.x:8265
tdarrDbID="" # ONLY used if TdarrScan.bash is used. The ID of the library you want to scan in Tdarr

View File

@@ -95,6 +95,10 @@ echo "Download Extras script..."
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/Extras.bash -o /config/extended/Extras.bash
echo "Done"
echo "Download TdarrScan script..."
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/TdarrScan.bash -o /config/extended/TdarrScan.bash
echo "Done"
if [ ! -f /config/extended/sma.ini ]; then
echo "Download SMA config..."
curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/sma.ini -o /config/extended/sma.ini