From 12f8b999bd4d5d749ad3ff3e8b1b55cb2a8cf29b Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Mon, 13 Jun 2022 15:56:50 +0000 Subject: [PATCH] Create PlexNotify.bash --- root/scripts/PlexNotify.bash | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 root/scripts/PlexNotify.bash diff --git a/root/scripts/PlexNotify.bash b/root/scripts/PlexNotify.bash new file mode 100644 index 0000000..edd169e --- /dev/null +++ b/root/scripts/PlexNotify.bash @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +PLEXURL="http://Your_Plex_IP:32400" +PLEXTOKEN="Your_Plex_Token" +lidarrApiKey="$(grep "" /config/config.xml | sed "s/\ //;s/<\/ApiKey>//")" +lidarrUrl="http://127.0.0.1:8686" +seriesId=$sonarr_series_id +seriesData=$(curl -s "http://localhost:8989/api/v3/series/$seriesId?apikey=$sonarrApiKey") +seriesPath="$(echo "$seriesData" | jq -r ".path")" +seriesRootFolderPath="$(echo "$seriesData" | jq -r ".rootFolderPath")" +plexfolder="$seriesPath" +exec &>> "/config/scripts/PlexNotify.log" + +log () { + m_time=`date "+%F %T"` + echo $m_time" "$1 +} + +if [ "$sonarr_eventtype" == "Test" ]; then + log "Tested" + exit 0 +fi + +plexlibraries="$(curl -s "$PLEXURL/library/sections?X-Plex-Token=$PLEXTOKEN" | xq .)" +if echo "$plexlibraries" | grep "$seriesRootFolderPath" | read; then + plexlibrarykey="$(echo "$plexlibraries" | jq -r ".MediaContainer.Directory[] | select(.Location.\"@path\"==\"$seriesRootFolderPath\") | .\"@key\"" | head -n 1)" + if [ -z "$plexlibrarykey" ]; then + log "ERROR: No Plex Library key found for \"$seriesRootFolderPath\"" + exit 1 + fi +else + log "ERROR: No Plex Library found containing path \"/$seriesRootFolderPath\"" + log "ERROR: Add \"/$seriesRootFolderPath\" as a folder to a Plex TV Library" + exit 1 +fi + +plexfolderencoded="$(jq -R -r @uri <<<"${plexfolder}")" +curl -s "$PLEXURL/library/sections/$plexlibrarykey/refresh?path=$plexfolderencoded&X-Plex-Token=$PLEXTOKEN" +log "Plex Scan notification sent! ($plexfolder)" + +exit 0