From 49feb39f47db738c2bb75ddf0767d4ce3ceb31af Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Tue, 15 Nov 2022 08:12:34 -0500 Subject: [PATCH] 1.0.279 - Updated Beets Proces, prevent duplicate imports for same release group --- root/scripts/Audio.sh | 50 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/root/scripts/Audio.sh b/root/scripts/Audio.sh index 9ce6e36..9898bd6 100644 --- a/root/scripts/Audio.sh +++ b/root/scripts/Audio.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -scriptVersion="1.0.278" +scriptVersion="1.0.279" if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" if [ "$lidarrUrlBase" == "null" ]; then @@ -667,8 +667,15 @@ DownloadProcess () { # Tag with beets if [ "$enableBeetsTagging" == "true" ]; then + if [ -f /config/extended/beets-error ]; then + rm /config/extended/beets-error + fi log "$processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: Processing files with beets..." ProcessWithBeets "$downloadPath/incomplete" + + if [ -f /config/extended/beets-error ]; then + return + fi fi # Embed Lyrics into Flac files @@ -800,12 +807,53 @@ ProcessWithBeets () { done else log "$processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: Unable to match using beets to a musicbrainz release..." + return fi if [ -f "/config/beets-match" ]; then rm "/config/beets-match" sleep 0.1 fi + + # get file extension + find "$downloadPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -print0 | while IFS= read -r -d '' audio; do + file="${audio}" + filenoext="${file%.*}" + filename="$(basename "$audio")" + extension="${filename##*.}" + breaK + done + + # Get file metadata + GetFile=$(find "$downloadPath/incomplete" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" | head -n1) + if [ "$extension" == "opus" ]; then + matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".streams[].tags") + else + matchedTags=$(ffprobe -hide_banner -loglevel fatal -show_error -show_format -show_streams -show_programs -show_chapters -show_private_data -print_format json "$GetFile" | jq -r ".format.tags") + fi + + # Get Musicbrainz Release Group ID and Album Artist ID from tagged file + if [ "$extension" == "flac" ] || [ "$extension" == "opus" ]; then + matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_RELEASEGROUPID")" + matchedTagsAlbumArtistId="$(echo $matchedTags | jq -r ".MUSICBRAINZ_ALBUMARTISTID")" + elif [ "$extension" == "mp3" ] || [ "$extension" == "m4a" ]; then + matchedTagsAlbumReleaseGroupId="$(echo $matchedTags | jq -r '."MusicBrainz Release Group Id"')" + matchedLidarrAlbumArtistId="$(echo $matchedTags | jq -r '."MusicBrainz Ablum Artist Id"')" + fi + + if [ ! -d "/config/extended/logs/downloaded/musicbrainz_matched" ]; then + mkdir -p "/config/extended/logs/downloaded/musicbrainz_matched" + chmod 777 "/config/extended/logs/downloaded/musicbrainz_matched" + fi + + if [ ! -f "/config/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId" ]; then + touch "/config/extended/logs/downloaded/musicbrainz_matched/$matchedTagsAlbumReleaseGroupId" + else + log "$processNumber of $wantedListAlbumTotal :: $lidarrArtistName :: $lidarrAlbumTitle :: $lidarrAlbumType :: ERROR :: MusicBrainz Release Group previously Downloaded ($matchedTagsAlbumReleaseGroupId) :: Removing and skipping to prevent duplicate import..." + rm -rf "$downloadPath/incomplete"/* + touch /config/extended/beets-error + fi + } DownloadQualityCheck () {