2023-09-08 20:29:56 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-09-09 21:11:08 +02:00
|
|
|
scriptVersion="1.6"
|
2023-09-08 23:40:18 +02:00
|
|
|
scriptName="BeetsTagger"
|
2023-09-08 20:29:56 +02:00
|
|
|
|
|
|
|
#### Import Settings
|
|
|
|
source /config/extended.conf
|
|
|
|
#### Import Functions
|
|
|
|
source /config/extended/functions
|
|
|
|
#### Create Log File
|
|
|
|
logfileSetup
|
|
|
|
|
|
|
|
SECONDS=0
|
|
|
|
|
|
|
|
if [ "$lidarr_eventtype" == "Test" ]; then
|
|
|
|
log "Tested Successfully"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
getArrAppInfo
|
|
|
|
verifyApiAccess
|
|
|
|
|
|
|
|
if [ -z "$lidarr_album_id" ]; then
|
|
|
|
lidarr_album_id="$1"
|
|
|
|
fi
|
|
|
|
|
2023-09-08 23:44:34 +02:00
|
|
|
if [ "$enableBeetsTagging" != "true" ]; then
|
|
|
|
log "Beets tagging is disabled, please enable by setting \"enableBeetsTagging=true\" in \"/config/extended.conf\""
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-09-08 20:29:56 +02:00
|
|
|
|
|
|
|
getAlbumArtist="$(curl -s "$arrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-Key: ${arrApiKey}" | jq -r .artist.artistName)"
|
|
|
|
getAlbumArtistPath="$(curl -s "$arrUrl/api/v1/album/$lidarr_album_id" -H "X-Api-Key: ${arrApiKey}" | jq -r .artist.path)"
|
|
|
|
getTrackPath="$(curl -s "$arrUrl/api/v1/trackFile?albumId=$lidarr_album_id" -H "X-Api-Key: ${arrApiKey}" | jq -r .[].path | head -n1)"
|
|
|
|
getFolderPath="$(dirname "$getTrackPath")"
|
|
|
|
getAlbumFolderName="$(basename "$getFolderPath")"
|
|
|
|
|
|
|
|
log "Processing :: $getAlbumFolderName :: Processing Files..."
|
|
|
|
|
|
|
|
if echo "$getFolderPath" | grep "$getAlbumArtistPath" | read; then
|
|
|
|
if [ ! -d "$getFolderPath" ]; then
|
|
|
|
log "ERROR :: \"$getFolderPath\" Folder is missing :: Exiting..."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
log "ERROR :: $getAlbumArtistPath not found within \"$getFolderPath\" :: Exiting..."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
ProcessWithBeets () {
|
|
|
|
log "$1 :: Start Processing..."
|
2023-09-09 15:17:39 +02:00
|
|
|
if find "$1" -type f -iname "*.flac" | read; then
|
2023-09-09 02:17:02 +02:00
|
|
|
sleep 0.01
|
|
|
|
else
|
2023-09-09 15:17:39 +02:00
|
|
|
log "$1 :: ERROR :: Only supports flac files, exiting..."
|
|
|
|
return
|
|
|
|
fi
|
2023-09-09 02:17:02 +02:00
|
|
|
SECONDS=0
|
2023-09-08 20:29:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Input
|
|
|
|
# $1 Download Folder to process
|
2023-09-08 23:40:18 +02:00
|
|
|
if [ -f /config/extended/library-lidarr.blb ]; then
|
|
|
|
rm /config/extended/library-lidarr.blb
|
2023-09-08 20:29:56 +02:00
|
|
|
sleep 0.5
|
|
|
|
fi
|
2023-09-09 21:11:08 +02:00
|
|
|
if [ -f /config/extended/extended/beets-lidarr.log ]; then
|
|
|
|
rm /config/extended/extended/beets-lidarr.log
|
2023-09-08 20:29:56 +02:00
|
|
|
sleep 0.5
|
|
|
|
fi
|
|
|
|
|
2023-09-08 23:40:18 +02:00
|
|
|
if [ -f "/config/extended/beets-lidarr-match" ]; then
|
|
|
|
rm "/config/extended/beets-lidarr-match"
|
2023-09-08 20:29:56 +02:00
|
|
|
sleep 0.5
|
|
|
|
fi
|
2023-09-08 23:40:18 +02:00
|
|
|
touch "/config/extended/beets-lidarr-match"
|
2023-09-08 20:29:56 +02:00
|
|
|
sleep 0.5
|
|
|
|
|
2023-09-09 20:19:55 +02:00
|
|
|
log "$1 :: Begin matching with beets!"
|
2023-09-09 21:11:08 +02:00
|
|
|
beet -c /config/extended/beets-config-lidarr.yaml -l /config/extended/library-lidarr.blb -d "$1" import -qC "$1" 2>&1 | tee -a /config/logs/$scriptName.txt
|
2023-09-09 00:01:00 +02:00
|
|
|
# Fix tags
|
|
|
|
log "$1 :: Fixing Tags..."
|
2023-09-08 20:29:56 +02:00
|
|
|
|
2023-09-09 00:01:00 +02:00
|
|
|
# Fix flac tags
|
|
|
|
fixed=0
|
|
|
|
find "$1" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do
|
|
|
|
if [ $fixed == 0 ]; then
|
|
|
|
fixed=$(( $fixed + 1 ))
|
|
|
|
log "$1 :: Fixing Flac Tags..."
|
|
|
|
fi
|
|
|
|
getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".format.tags.ARTIST_CREDIT" | sed "s/null//g" | sed "/^$/d")"
|
|
|
|
metaflac --remove-tag=ARTIST "$file"
|
|
|
|
metaflac --remove-tag=ALBUMARTIST "$file"
|
|
|
|
metaflac --remove-tag=ALBUMARTIST_CREDIT "$file"
|
|
|
|
metaflac --remove-tag=ALBUMARTISTSORT "$file"
|
|
|
|
metaflac --remove-tag=ALBUM_ARTIST "$file"
|
|
|
|
metaflac --remove-tag="ALBUM ARTIST" "$file"
|
|
|
|
metaflac --remove-tag=ARTISTSORT "$file"
|
|
|
|
metaflac --remove-tag=COMPOSERSORT "$file"
|
|
|
|
metaflac --set-tag=ALBUMARTIST="$getAlbumArtist" "$file"
|
|
|
|
if [ ! -z "$getArtistCredit" ]; then
|
|
|
|
metaflac --set-tag=ARTIST="$getArtistCredit" "$file"
|
2023-09-08 20:29:56 +02:00
|
|
|
else
|
2023-09-09 00:01:00 +02:00
|
|
|
metaflac --set-tag=ARTIST="$getAlbumArtist" "$file"
|
|
|
|
fi
|
|
|
|
done
|
2023-09-08 20:29:56 +02:00
|
|
|
|
2023-09-09 00:01:00 +02:00
|
|
|
log "$1 :: Fixing Tags Complete!"
|
|
|
|
|
2023-09-08 20:29:56 +02:00
|
|
|
|
2023-09-08 23:40:18 +02:00
|
|
|
if [ -f "/config/extended/beets-lidarr-match" ]; then
|
|
|
|
rm "/config/extended/beets-lidarr-match"
|
2023-09-08 20:29:56 +02:00
|
|
|
sleep 0.5
|
|
|
|
fi
|
|
|
|
|
2023-09-08 23:40:18 +02:00
|
|
|
if [ -f /config/extended/library-lidarr.blb ]; then
|
|
|
|
rm /config/extended/library-lidarr.blb
|
2023-09-08 20:29:56 +02:00
|
|
|
sleep 0.5
|
|
|
|
fi
|
|
|
|
if [ -f /config/extended/logs/beets.log ]; then
|
|
|
|
rm /config/extended/logs/beets.log
|
|
|
|
sleep 0.5
|
|
|
|
fi
|
|
|
|
|
|
|
|
duration=$SECONDS
|
|
|
|
log "$1 :: Finished in $(($duration / 60 )) minutes and $(($duration % 60 )) seconds!"
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessWithBeets "$getFolderPath"
|
|
|
|
exit
|