diff --git a/radarr/AutoConfig.service b/radarr/AutoConfig.service index 5238b8f..6a2a41e 100644 --- a/radarr/AutoConfig.service +++ b/radarr/AutoConfig.service @@ -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 diff --git a/radarr/TdarrScan.bash b/radarr/TdarrScan.bash new file mode 100644 index 0000000..de39169 --- /dev/null +++ b/radarr/TdarrScan.bash @@ -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 diff --git a/radarr/extended.conf b/radarr/extended.conf index d7309cc..e4d353a 100644 --- a/radarr/extended.conf +++ b/radarr/extended.conf @@ -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 diff --git a/radarr/setup.bash b/radarr/setup.bash index aa4296f..ba53a78 100644 --- a/radarr/setup.bash +++ b/radarr/setup.bash @@ -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 diff --git a/sonarr/AutoConfig.service b/sonarr/AutoConfig.service index cb36e5b..50194a6 100644 --- a/sonarr/AutoConfig.service +++ b/sonarr/AutoConfig.service @@ -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 diff --git a/sonarr/TdarrScan.bash b/sonarr/TdarrScan.bash new file mode 100644 index 0000000..1a862f3 --- /dev/null +++ b/sonarr/TdarrScan.bash @@ -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 diff --git a/sonarr/extended.conf b/sonarr/extended.conf index 8c415c8..ca707e6 100644 --- a/sonarr/extended.conf +++ b/sonarr/extended.conf @@ -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 diff --git a/sonarr/setup.bash b/sonarr/setup.bash index 4bb29f4..2309c54 100644 --- a/sonarr/setup.bash +++ b/sonarr/setup.bash @@ -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