You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.7 KiB

#!/usr/bin/env bash
2 years ago
scriptVersion=1.0.5
if [ -z "$lidarr_artist_path" ]; then
lidarr_artist_path="$1"
notfidedBy=Extended_Script
else
notfidedBy=Lidarr
fi
2 years ago
lidarrRootFolderPath="$(dirname "$lidarr_artist_path")"
# auto-clean up log file to reduce space usage
2 years ago
if [ -f "/config/logs/PlexNotify.txt" ]; then
find /config/logs -type f -name "PlexNotify.txt" -size +1024k -delete
fi
2 years ago
exec &> >(tee -a "/config/logs/PlexNotify.txt")
chmod 666 "/config/logs/PlexNotify.txt"
log () {
m_time=`date "+%F %T"`
2 years ago
echo $m_time" :: PlexNotify :: $scriptVersion :: "$1
}
2 years ago
if [ "$lidarr_eventtype" == "Test" ]; then
log "$notfidedBy :: Tested Successfully"
exit 0
fi
# Validate connection
plexVersion=$(curl -s "$plexUrl/?X-Plex-Token=$plexToken" | xq . | jq -r '.MediaContainer."@version"')
if [ $plexVersion = null ]; then
log "$notfidedBy :: ERROR :: Cannot communicate with Plex"
log "$notfidedBy :: ERROR :: Please check your plexUrl and plexToken"
log "$notfidedBy :: ERROR :: Configured plexUrl \"$plexUrl\""
log "$notfidedBy :: ERROR :: Configured plexToken \"$plexToken\""
log "$notfidedBy :: ERROR :: Exiting..."
exit
else
log "$notfidedBy :: Plex Connection Established, version: $plexVersion"
fi
2 years ago
2 years ago
plexLibraries="$(curl -s "$plexUrl/library/sections?X-Plex-Token=$plexToken")"
if echo "$plexLibraries" | xq ".MediaContainer.Directory | select(.\"@type\"==\"artist\")" &>/dev/null; then
plexKeys=($(echo "$plexLibraries" | xq ".MediaContainer.Directory | select(.\"@type\"==\"artist\")" | jq -r '."@key"'))
plexLibraryData=$(echo "$plexLibraries" | xq ".MediaContainer.Directory | select(.\"@type\"==\"artist\")")
elif echo "$plexLibraries" | xq ".MediaContainer.Directory[] | select(.\"@type\"==\"artist\")" &>/dev/null; then
plexKeys=($(echo "$plexLibraries" | xq ".MediaContainer.Directory[] | select(.\"@type\"==\"artist\")" | jq -r '."@key"'))
plexLibraryData=$(echo "$plexLibraries" | xq ".MediaContainer.Directory[] | select(.\"@type\"==\"artist\")")
else
log "$notfidedBy :: ERROR: No Plex Music Type libraries found"
log "$notfidedBy :: ERROR: Exiting..."
2 years ago
exit 1
fi
2 years ago
if echo "$plexLibraryData" | grep "\"@path\": \"$lidarrRootFolderPath" | read; then
sleep 0.01
2 years ago
else
log "$notfidedBy :: ERROR: No Plex Library found containing path \"$lidarrRootFolderPath\""
log "$notfidedBy :: ERROR: Add \"$lidarrRootFolderPath\" as a folder to a Plex Music Library"
2 years ago
exit 1
fi
2 years ago
for key in ${!plexKeys[@]}; do
plexKey="${plexKeys[$key]}"
if echo "$plexLibraryData" | grep "\"@path\": \"$lidarrRootFolderPath" | read; then
plexFolderEncoded="$(jq -R -r @uri <<<"$lidarr_artist_path")"
2 years ago
curl -s "$plexUrl/library/sections/$plexKey/refresh?path=$plexFolderEncoded&X-Plex-Token=$plexToken"
log "$notfidedBy :: Plex Scan notification sent! ($lidarr_artist_path)"
2 years ago
fi
done
2 years ago
exit 0