From 2093d5089cb01b2306e57ed2e5d1fae16056e91e Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Fri, 18 Nov 2022 09:15:48 -0500 Subject: [PATCH] 1.0.008 - improved tag fix process... Now fixes opus tags --- root/scripts/BeetsPostProcessor.bash | 35 +++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/root/scripts/BeetsPostProcessor.bash b/root/scripts/BeetsPostProcessor.bash index 30ef178..5e3c868 100644 --- a/root/scripts/BeetsPostProcessor.bash +++ b/root/scripts/BeetsPostProcessor.bash @@ -1,5 +1,5 @@ #!/usr/bin/env bash -version=1.0.007 +version=1.0.008 if [ -z "$lidarrUrl" ] || [ -z "$lidarrApiKey" ]; then lidarrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)" if [ "$lidarrUrlBase" == "null" ]; then @@ -69,8 +69,17 @@ ProcessWithBeets () { log "$1 :: Being matching with beets!" beet -c /config/extended/scripts/beets-config.yaml -l /config/library-postprocessor.blb -d "$1" import -qC "$1" if [ $(find "$1" -type f -regex ".*/.*\.\(flac\|opus\|m4a\|mp3\)" -newer "/config/beets-postprocessor-match" | wc -l) -gt 0 ]; then - log "$1 :: SUCCESS: Matched with beets!" + log "$1 :: SUCCESS :: Matched with beets!" + + # Fix tags + log "$1 :: Fixing Tags..." + + # Fix flac tags + fixed=0 find "$1" -type f -iname "*.flac" -print0 | while IFS= read -r -d '' file; do + if [ $fixed == 0 ]; then + 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" @@ -80,8 +89,28 @@ ProcessWithBeets () { metaflac --remove-tag="ALBUM ARTIST" "$file" metaflac --remove-tag=ARTISTSORT "$file" metaflac --set-tag=ALBUMARTIST="$getAlbumArtist" "$file" - metaflac --set-tag=ARTIST="$getArtistCredit" "$file" + if [ ! -z "$getArtistCredit" ]; then + metaflac --set-tag=ARTIST="$getArtistCredit" "$file" + else + metaflac --set-tag=ARTIST="$getAlbumArtist" "$file" + fi done + + # Fix opus tags + fixed=0 + find "$1" -type f -iname "*.opus" -print0 | while IFS= read -r -d '' file; do + if [ $fixed == 0 ]; then + log "$1 :: Fixing OPUS Tags..." + fi + getArtistCredit="$(ffprobe -loglevel 0 -print_format json -show_format -show_streams "$file" | jq -r ".streams[].tags.ARTIST_CREDIT" 2>/dev/null | sed "s/null//g" | sed "/^$/d")" + if [ ! -z "$getArtistCredit" ]; then + python3 "/config/extended/scripts/tag_opus.py" --file "$file" --songartist "$getArtistCredit" --songalbumartist "$getAlbumArtist" + else + python3 "/config/extended/scripts/tag_opus.py" --file "$file" --songartist "$getAlbumArtist" --songalbumartist "$getAlbumArtist" + fi + done + + log "$1 :: Fixing Tags Complete!" else log "$1 :: ERROR :: Unable to match using beets to a musicbrainz release..." fi