From a58a5c24268a4c257ab13c30931f69324efb9db3 Mon Sep 17 00:00:00 2001 From: Vegard Fladby Date: Fri, 6 Sep 2024 13:10:29 +0200 Subject: [PATCH 1/3] Sonarr -> Emby notification --- sonarr/Extras.bash | 26 ++++++++++++++++++++++++++ sonarr/extended.conf | 4 ++++ sonarr/setup.bash | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/sonarr/Extras.bash b/sonarr/Extras.bash index 3c968609..1d3864cb 100644 --- a/sonarr/Extras.bash +++ b/sonarr/Extras.bash @@ -5,6 +5,7 @@ arrItemId=$sonarr_series_id tmdbApiKey="3b7751e3179f796565d88fdb2fcdf426" autoScan="false" updatePlex="false" +updateEmby="false" ytdlpExtraOpts="--user-agent facebookexternalhit/1.1" scriptName="Extras" @@ -178,6 +179,7 @@ DownloadExtras () { fi updatePlex="true" + updateEmby="true" done done @@ -214,6 +216,28 @@ NotifyPlex () { fi } +NotifyEmby () { + # Process item with EmbyNotify.bash if EmbyToken is configured + if [ ! -z "$embyApiKey" ]; then + # Always update Emby if extra is downloaded + if [ "$updateEmby" == "true" ]; then + log "$itemTitle :: Using EmbyNotify.bash to update Emby...." + bash /config/extended/EmbyNotify.bash "$itemPath" + exit + fi + + # Do not notify Emby if this script was triggered by the AutoExtras.bash and no Extras were downloaded + if [ "$autoScan" == "true" ]; then + log "$itemTitle :: Skipping Emby notification, not needed...." + exit + else + log "$itemTitle :: Using EmbyNotify.bash to update Emby...." + bash /config/extended/EmbyNotify.bash "$itemPath" + exit + fi + fi +} + # Check if series has been previously processed if [ -f "/config/extended/logs/extras/$tmdbId" ]; then # Delete log file older than 7 days, to allow re-processing @@ -223,10 +247,12 @@ fi if [ -f "/config/extended/logs/extras/$tmdbId" ]; then log "$itemTitle :: Already processed Extras, waiting 7 days to re-check..." NotifyPlex + NotifyEmby exit else DownloadExtras NotifyPlex + NotifyEmby fi exit diff --git a/sonarr/extended.conf b/sonarr/extended.conf index 8c415c8b..5285913e 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 + +#### EMBY NOTIFY SCRIPT +embyUrl="" # ONLY used if EmbyNotify.bash is used, example: http://x.x.x.x:8096 +embyApiKey="" # ONLY used if EmbyNotify.bash is used \ No newline at end of file diff --git a/sonarr/setup.bash b/sonarr/setup.bash index 078a7f1c..a2531bc9 100644 --- a/sonarr/setup.bash +++ b/sonarr/setup.bash @@ -79,6 +79,10 @@ echo "Download PlexNotify script..." curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/PlexNotify.bash -o /config/extended/PlexNotify.bash echo "Done" +echo "Download EmbyNotify script..." +curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/EmbyNotify.bash -o /config/extended/EmbyNotify.bash +echo "Done" + echo "Download DailySeriesEpisodeTrimmer script..." curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/sonarr/DailySeriesEpisodeTrimmer.bash -o /config/extended/DailySeriesEpisodeTrimmer.bash echo "Done" From 2c3b39f44bc1e148e0f8e26f395a57722b32a7b3 Mon Sep 17 00:00:00 2001 From: Vegard Fladby Date: Fri, 6 Sep 2024 13:21:26 +0200 Subject: [PATCH 2/3] Radarr -> Emby notification +bugfix Sonarr --- radarr/AutoConfig.service | 23 ++++++++++++++++------- radarr/Extras.bash | 21 +++++++++++++++++++++ radarr/extended.conf | 4 ++++ radarr/setup.bash | 4 ++++ sonarr/AutoConfig.service | 33 ++++++++++++++++++++++----------- sonarr/Extras.bash | 2 +- 6 files changed, 68 insertions(+), 19 deletions(-) diff --git a/radarr/AutoConfig.service b/radarr/AutoConfig.service index 5238b8ff..ee90ad70 100644 --- a/radarr/AutoConfig.service +++ b/radarr/AutoConfig.service @@ -58,16 +58,25 @@ if [ "$configureMetadataProviderSettings" == "true" ] || [ -z "$configureMetadat log "Complete" fi -if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ]; then +configure_script() { + scriptName=$1 + scriptPath=$2 + log "Configuring Radarr Custom Scripts" - if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "PlexNotify.bash" | read; then - log "PlexNotify.bash already added to Radarr custom scripts" + if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "$scriptName" | read; then + log "$scriptName already added to Radarr custom scripts" else - log "Adding PlexNotify.bash to Radarr custom scripts" - updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2Fscripts%2FPlexNotify.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":true,"onMovieAdded":false,"onMovieDelete":false,"onMovieFileDelete":true,"onMovieFileDeleteForUpgrade":true,"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":"PlexNotify.bash","fields":[{"name":"path","value":"/config/extended/PlexNotify.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" + log "Adding $scriptName to Radarr custom scripts" + updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2Fscripts%2F$scriptPath&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":true,"onMovieAdded":false,"onMovieDelete":false,"onMovieFileDelete":true,"onMovieFileDeleteForUpgrade":true,"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":"'$scriptName'","fields":[{"name":"path","value":"/config/extended/'$scriptPath'"},{"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 +} + +if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ]; then + configure_script "PlexNotify.bash" "PlexNotify.bash" + configure_script "EmbyNotify.bash" "EmbyNotify.bash" +fi if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "Extras.bash" | read; then log "Extras.bash already added to Radarr custom scripts" diff --git a/radarr/Extras.bash b/radarr/Extras.bash index bdca75d6..0e00cbdc 100644 --- a/radarr/Extras.bash +++ b/radarr/Extras.bash @@ -5,6 +5,7 @@ arrItemId=$radarr_movie_id tmdbApiKey="3b7751e3179f796565d88fdb2fcdf426" autoScan="false" updatePlex="false" +updateEmby="false" ytdlpExtraOpts="--user-agent facebookexternalhit/1.1" scriptName="Extras" @@ -239,6 +240,7 @@ do fi updatePlex="true" + updateEmby="true" if [ "$extrasSingle" == "true" ]; then log "$itemTitle :: $i of $tmdbVideosListDataIdsCount :: $tmdbExtraType :: Finished processing single trailer download" @@ -268,5 +270,24 @@ if [ ! -z "$plexToken" ]; then exit fi fi +# Process item with EmbyNotify.bash if embyApiKey is configured +if [ ! -z "$embyApiKey" ]; then + # Always update Emby if extra is downloaded + if [ "$updateEmby" == "true" ]; then + log "Using EmbyNotify.bash to update Emby...." + bash /config/extended/EmbyNotify.bash "$itemPath" + exit + fi + + # Do not notify emby if this script was triggered by the AutoExtras.bash and no Extras were downloaded + if [ "$autoScan" == "true" ]; then + log "Skipping Emby notification, not needed...." + exit + else + log "Using EmbyNotify.bash to update Emby...." + bash /config/extended/EmbyNotify.bash "$itemPath" + exit + fi +fi exit diff --git a/radarr/extended.conf b/radarr/extended.conf index d7309cc9..6475c856 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 + +#### EMBY NOTIFY SCRIPT +embyUrl="" # ONLY used if EmbyNotify.bash is used, example: http://x.x.x.x:8096 +embyApiKey="" # ONLY used if EmbyNotify.bash is used \ No newline at end of file diff --git a/radarr/setup.bash b/radarr/setup.bash index 9aafe005..d5927731 100644 --- a/radarr/setup.bash +++ b/radarr/setup.bash @@ -81,6 +81,10 @@ echo "Download PlexNotify script..." curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/PlexNotify.bash -o /config/extended/PlexNotify.bash echo "Done" +echo "Download EmbyNotify script..." +curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/EmbyNotify.bash -o /config/extended/EmbyNotify.bash +echo "Done" + echo "Download Extras script..." curl https://raw.githubusercontent.com/RandomNinjaAtk/arr-scripts/main/radarr/Extras.bash -o /config/extended/Extras.bash echo "Done" diff --git a/sonarr/AutoConfig.service b/sonarr/AutoConfig.service index cb36e5bd..6c13e5d7 100644 --- a/sonarr/AutoConfig.service +++ b/sonarr/AutoConfig.service @@ -68,20 +68,31 @@ if [ "$configureMetadataProviderSettings" == "true" ] || [ -z "$configureMetadat updateArr=$(curl -s "$arrUrl/api/v3/metadata/4?" -X PUT -H "Content-Type: application/json" -H "X-Api-Key: $arrApiKey" --data-raw '{"enable":true,"name":"Plex","fields":[{"name":"seriesPlexMatchFile","value":true}],"implementationName":"Plex","implementation":"PlexMetadata","configContract":"PlexMetadataSettings","infoLink":"https://wiki.servarr.com/sonarr/supported#plexmetadata","tags":[],"id":4}') fi -if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ]; then +configure_script() { + scriptName=$1 + scriptPath=$2 + log "Configuring Sonarr Custom Scripts" - if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "PlexNotify.bash" | read; then - log "PlexNotify.bash already added to Sonarr custom scripts" + if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "$scriptName" | read; then + log "$scriptName already added to Sonarr custom scripts" else - log "Adding PlexNotify.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%2FPlexNotify.bash&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}") - - # Add PlexNotify.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":true,"onSeriesDelete":true,"onEpisodeFileDelete":true,"onEpisodeFileDeleteForUpgrade":true,"onHealthIssue":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnDownload":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnSeriesDelete":true,"supportsOnEpisodeFileDelete":true,"supportsOnEpisodeFileDeleteForUpgrade":true,"supportsOnHealthIssue":true,"supportsOnApplicationUpdate":true,"includeHealthWarnings":false,"name":"PlexNotify.bash","fields":[{"name":"path","value":"/config/extended/PlexNotify.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" + log "Adding $scriptName to Sonarr custom scripts" + # Check file path + updateArr=$(curl -s "$arrUrl/api/v3/filesystem?path=%2Fconfig%2Fextended%2Fscripts%2F$scriptPath&allowFoldersWithoutTrailingSlashes=true&includeFiles=true" -H "X-Api-Key: ${arrApiKey}") + + # Add script + 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":true,"onEpisodeFileDelete":true,"onEpisodeFileDeleteForUpgrade":true,"onHealthIssue":false,"onApplicationUpdate":false,"supportsOnGrab":true,"supportsOnDownload":true,"supportsOnUpgrade":true,"supportsOnRename":true,"supportsOnSeriesDelete":true,"supportsOnEpisodeFileDelete":true,"supportsOnEpisodeFileDeleteForUpgrade":true,"supportsOnHealthIssue":true,"supportsOnApplicationUpdate":true,"includeHealthWarnings":false,"name":"'$scriptName'","fields":[{"name":"path","value":"/config/extended/'$scriptPath'"},{"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 - +} + +if [ "$configureCustomScripts" == "true" ] || [ -z "$configureCustomScripts" ]; then + # For Sonarr + configure_script "PlexNotify.bash" "PlexNotify.bash" + configure_script "EmbyNotify.bash" "EmbyNotify.bash" +fi + + if curl -s "$arrUrl/api/v3/notification" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].name | grep "DailySeriesEpisodeTrimmer.bash" | read; then log "DailySeriesEpisodeTrimmer.bash already added to Sonarr custom scripts" else diff --git a/sonarr/Extras.bash b/sonarr/Extras.bash index 1d3864cb..c238ee1e 100644 --- a/sonarr/Extras.bash +++ b/sonarr/Extras.bash @@ -217,7 +217,7 @@ NotifyPlex () { } NotifyEmby () { - # Process item with EmbyNotify.bash if EmbyToken is configured + # Process item with EmbyNotify.bash if embyApiKey is configured if [ ! -z "$embyApiKey" ]; then # Always update Emby if extra is downloaded if [ "$updateEmby" == "true" ]; then From 216463135e8e486566cd05da182c8ea247e57a51 Mon Sep 17 00:00:00 2001 From: Vegard Fladby Date: Fri, 6 Sep 2024 13:21:45 +0200 Subject: [PATCH 3/3] Add all files... --- radarr/EmbyNotify.bash | 79 +++++++++++++++++++++++++++++++++++ sonarr/EmbyNotify.bash | 95 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 radarr/EmbyNotify.bash create mode 100644 sonarr/EmbyNotify.bash diff --git a/radarr/EmbyNotify.bash b/radarr/EmbyNotify.bash new file mode 100644 index 00000000..e5f632d7 --- /dev/null +++ b/radarr/EmbyNotify.bash @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +scriptVersion="1.0" +scriptName="EmbyNotify" + +#### Import Settings +source /config/extended.conf # This will import embyUrl and embyApiKey + +log () { + m_time=$(date "+%F %T") + echo "$m_time :: $scriptName :: $scriptVersion :: $1" +} + +notifiedBy="Radarr" +arrRootFolderPath="$(dirname "$radarr_movie_path")" +arrFolderPath="$radarr_movie_path" +arrEventType="$radarr_eventtype" +movieExtrasPath="$1" + +# auto-clean up log file to reduce space usage +if [ -f "/config/logs/EmbyNotify.txt" ]; then + find /config/logs -type f -name "EmbyNotify.txt" -size +1024k -delete +fi + +if [ ! -f "/config/logs/EmbyNotify.txt" ]; then + touch "/config/logs/EmbyNotify.txt" + chmod 777 "/config/logs/EmbyNotify.txt" +fi +exec &> >(tee -a "/config/logs/EmbyNotify.txt") + +if [ "$arrEventType" == "Test" ]; then + log "$notifiedBy :: Tested Successfully" + exit 0 +fi + +EmbyConnectionError () { + log "ERROR :: Cannot communicate with Emby" + log "ERROR :: Please check your embyUrl and embyApiKey" + log "ERROR :: Configured embyUrl \"$embyUrl\"" + log "ERROR :: Configured embyApiKey \"$embyApiKey\"" + log "ERROR :: Exiting..." + exit +} + +# Validate connection +if curl -s "$embyUrl/emby/System/Info?api_key=$embyApiKey" | jq . &>/dev/null; then + embyVersion=$(curl -s "$embyUrl/emby/System/Info?api_key=$embyApiKey" | jq -r '.Version') + if [ -z "$embyVersion" ]; then + # Error out if version is null, indicates bad token + EmbyConnectionError + else + log "Emby Connection Established, version: $embyVersion" + fi +else + # Error out if error in curl | jq . command output + EmbyConnectionError +fi + +# Get Emby libraries +embyLibraries=$(curl -s "$embyUrl/emby/Library/VirtualFolders?api_key=$embyApiKey") +if [[ -z "$embyLibraries" ]]; then + log "$notifiedBy :: ERROR: Failed to retrieve libraries from Emby" + exit 1 +fi + +# Find matching Emby library for the given path +embyLibraryId=$(echo "$embyLibraries" | jq -r ".[] | select(.Locations[] | contains(\"$arrRootFolderPath\")) | .CollectionType") + +if [[ -z "$embyLibraryId" ]]; then + log "$notifiedBy :: ERROR: No Emby Library found containing path \"$arrRootFolderPath\"" + log "$notifiedBy :: ERROR: Add \"$arrRootFolderPath\" as a folder to an Emby Library" + exit 1 +else + # Refresh only the relevant folder using its path + log "$notifiedBy :: Emby Library found for path \"$arrRootFolderPath\", refreshing..." + curl -X POST "$embyUrl/emby/Items/$embyLibraryId/Refresh?api_key=$embyApiKey" + log "$notifiedBy :: Emby Scan notification sent for folder: $arrFolderPath" +fi + +exit diff --git a/sonarr/EmbyNotify.bash b/sonarr/EmbyNotify.bash new file mode 100644 index 00000000..c2f50cd3 --- /dev/null +++ b/sonarr/EmbyNotify.bash @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +scriptVersion="1.0" +notifiedBy="Sonarr" +arrRootFolderPath="$(dirname "$sonarr_series_path")" +arrFolderPath="$sonarr_series_path" +arrEventType="$sonarr_eventtype" +extrasPath="$1" +scriptName="EmbyNotify" + +#### Import Settings +source /config/extended.conf # Assuming you have embyUrl and embyApiKey in this config file + +log () { + m_time=`date "+%F %T"` + echo "$m_time :: $scriptName :: $scriptVersion :: $1" +} + +# Auto-clean up log file to reduce space usage +if [ -f "/config/logs/EmbyNotify.txt" ]; then + find /config/logs -type f -name "EmbyNotify.txt" -size +1024k -delete +fi + +if [ ! -f "/config/logs/EmbyNotify.txt" ]; then + touch "/config/logs/EmbyNotify.txt" + chmod 666 "/config/logs/EmbyNotify.txt" +fi +exec &> >(tee -a "/config/logs/EmbyNotify.txt") + +# If extras are enabled, update paths +if [ "$enableExtras" == "true" ]; then + if [ -z "$extrasPath" ]; then + log "Extras script is enabled, skipping..." + exit + fi +fi + +if [ ! -z "$extrasPath" ]; then + arrFolderPath="$extrasPath" + if [ "$2" == "true" ]; then + arrRootFolderPath="$extrasPath" + else + arrRootFolderPath="$(dirname "$extrasPath")" + fi +fi + +if [ "$arrEventType" == "Test" ]; then + log "$notifiedBy :: Tested Successfully" + exit 0 +fi + +embyConnectionError () { + log "ERROR :: Cannot communicate with Emby" + log "ERROR :: Please check your embyUrl and embyApiKey" + log "ERROR :: Configured embyUrl \"$embyUrl\"" + log "ERROR :: Configured embyApiKey \"$embyApiKey\"" + log "ERROR :: Exiting..." + exit +} + +# Validate connection +if curl -s "$embyUrl/emby/System/Info?api_key=$embyApiKey" | jq . &>/dev/null; then + embyVersion=$(curl -s "$embyUrl/emby/System/Info?api_key=$embyApiKey" | jq -r '.Version') + if [ -z "$embyVersion" ]; then + # Error out if version is null, indicates bad token + embyConnectionError + else + log "Emby Connection Established, version: $embyVersion" + fi +else + # Error out if error in curl | jq . command output + embyConnectionError +fi + +# Get Emby libraries +embyLibraries=$(curl -s "$embyUrl/emby/Library/VirtualFolders?api_key=$embyApiKey") +if [[ -z "$embyLibraries" ]]; then + log "$notifiedBy :: ERROR: Failed to retrieve libraries from Emby" + exit 1 +fi + +# Find matching Emby library for the given path +embyLibraryId=$(echo "$embyLibraries" | jq -r ".[] | select(.Locations[] | contains(\"$arrRootFolderPath\")) | .CollectionType") + +if [[ -z "$embyLibraryId" ]]; then + log "$notifiedBy :: ERROR: No Emby Library found containing path \"$arrRootFolderPath\"" + log "$notifiedBy :: ERROR: Add \"$arrRootFolderPath\" as a folder to an Emby Library" + exit 1 +else + # Refresh only the relevant folder using its path + log "$notifiedBy :: Emby Library found for path \"$arrRootFolderPath\", refreshing..." + curl -X POST "$embyUrl/emby/Items/$embyLibraryId/Refresh?api_key=$embyApiKey" + log "$notifiedBy :: Emby Scan notification sent for folder: $arrFolderPath" +fi + +exit