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.

60 lines
2.0 KiB

#!/usr/bin/env bash
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 &>> "/config/logs/PlexNotify.txt"
chmod 777 "/config/logs/PlexNotify.txt"
log () {
m_time=`date "+%F %T"`
echo $m_time" :: "$1
}
2 years ago
if [ "$lidarr_eventtype" == "Test" ]; then
2 years ago
log "Tested Successfully"
exit 0
fi
2 years ago
until false
do
taskCount=$(ps aux | grep Plex_MusicVideos.bash | grep -v grep | wc -l)
if [ "$taskCount" -ge "1" ]; then
sleep 1
else
break
2 years ago
fi
2 years ago
done
2 years ago
2 years ago
plexLibraries="$(curl -s "$plexUrl/library/sections?X-Plex-Token=$plexToken" | xq .)"
if echo "$plexLibraries" | grep "$lidarrRootFolderPath" | read; then
if echo "$plexLibraries" | jq -r ".MediaContainer.Directory[] | select(.Location.\"@path\"==\"$lidarrRootFolderPath\") | .\"@key\"" &>/dev/null; then
plexlibrarykey="$(echo "$plexLibraries" | jq -r ".MediaContainer.Directory[] | select(.Location.\"@path\"==\"$lidarrRootFolderPath\") | .\"@key\"" | head -n 1)"
else
plexlibrarykey="$(echo "$plexLibraries" | jq -r ".MediaContainer.Directory | select(.Location.\"@path\"==\"$lidarrRootFolderPath\") | .\"@key\"" | head -n 1)"
fi
2 years ago
if [ -z "$plexlibrarykey" ]; then
log "ERROR: No Plex Library key found for \"$lidarrRootFolderPath\""
exit 1
fi
2 years ago
else
if echo "$plexLibraries" | grep -i "Unauthorized" | read; then
log "ERROR :: Cannot connect to Plex"
log "ERROR :: plexUrl or plexToken is invalid"
log "ERROR :: plexUrl is currently set to \"$plexUrl\""
log "ERROR :: plexToken is currently set to \"$plexToken\""
exit 1
else
2 years ago
log "ERROR: No Plex Library found containing path \"$lidarrRootFolderPath\""
log "ERROR: Add \"$lidarrRootFolderPath\" as a folder to a Plex Music Library"
exit 1
fi
fi
2 years ago
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! ($lidarr_artist_path)"
exit 0