Update PlexNotify.bash

pull/6/head
RandomNinjaAtk 2 years ago committed by GitHub
parent 6fe4847371
commit a784ac4000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,11 +1,8 @@
#!/usr/bin/env bash
PLEXURL="http://$plexIp:32400"
PLEXTOKEN="$plexToken"
lidarrApiKey="$(grep "<ApiKey>" /config/config.xml | sed "s/\ <ApiKey>//;s/<\/ApiKey>//")"
lidarrUrl="http://127.0.0.1:8686"
lidarrRootFolderPath="$(dirname "$Lidarr_Artist_Path")"
plexfolder="$Lidarr_Artist_Path"
exec &>> "/config/scripts/PlexNotify.log"
exec &>> "/config/logs/PlexNotify.log"
log () {
m_time=`date "+%F %T"`
@ -17,21 +14,21 @@ if [ "$Lidarr_EventType" == "Test" ]; then
exit 0
fi
plexlibraries="$(curl -s "$PLEXURL/library/sections?X-Plex-Token=$PLEXTOKEN" | xq .)"
if echo "$plexlibraries" | grep "$lidarrRootFolderPath" | read; then
plexlibrarykey="$(echo "$plexlibraries" | jq -r ".MediaContainer.Directory[] | select(.Location.\"@path\"==\"$lidarrRootFolderPath\") | .\"@key\"" | head -n 1)"
plexLibraries="$(curl -s "$plexUrl/library/sections?X-Plex-Token=$plexToken" | xq .)"
if echo "$plexLibraries" | grep "$lidarrRootFolderPath" | read; then
plexlibrarykey="$(echo "$plexLibraries" | jq -r ".MediaContainer.Directory[] | select(.Location.\"@path\"==\"$lidarrRootFolderPath\") | .\"@key\"" | head -n 1)"
if [ -z "$plexlibrarykey" ]; then
log "ERROR: No Plex Library key found for \"$lidarrRootFolderPath\""
exit 1
fi
else
log "ERROR: No Plex Library found containing path \"/$lidarrRootFolderPath\""
log "ERROR: Add \"/$lidarrRootFolderPath\" as a folder to a Plex Music Library"
log "ERROR: Add \"/$lidarrRootFolderPath\" 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"
plexFolderEncoded="$(jq -R -r @uri <<<"$Lidarr_Artist_Path")"
curl -s "$plexUrl/library/sections/$plexlibrarykey/refresh?path=$plexFolderEncoded&X-Plex-Token=$plexToken"
log "Plex Scan notification sent! ($plexfolder)"
exit 0

Loading…
Cancel
Save