From bdc18dd7275b41941a63e18b8721a7188491fd45 Mon Sep 17 00:00:00 2001
From: Hyperling <me@hyperling.com>
Date: Sun, 13 Apr 2025 11:47:33 -0700
Subject: [PATCH] Only check additonal band slots if the more important ones
 are empty. Fix bug in if statement, was checking wrong variable.

---
 refactor_music_library.sh | 42 +++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/refactor_music_library.sh b/refactor_music_library.sh
index bcaf9bc..f97be32 100755
--- a/refactor_music_library.sh
+++ b/refactor_music_library.sh
@@ -187,30 +187,34 @@ function migrate_music {
 	echo "*** Artist=$artist"
 
 	band=""
-	band="`exiftool -Band "$file"`"
-	band="${band//Band   /}"
-	band="${band//   : /}"
-	band="${band//[^[:alnum:][:space:].]/}"
-	band="`echo $band`"
-	while [[ "$band" == *"  "* ]]; do
-		band="${band//  / }"
-	done
-	echo "*** Band=$band"
+	if [[ -z "$artist" ]]; then
+		band="`exiftool -Band "$file"`"
+		band="${band//Band   /}"
+		band="${band//   : /}"
+		band="${band//[^[:alnum:][:space:].]/}"
+		band="`echo $band`"
+		while [[ "$band" == *"  "* ]]; do
+			band="${band//  / }"
+		done
+		echo "*** Band=$band"
+	fi
 
 	album_artist=""
-	album_artist="`exiftool -Albumartist "$file"`"
-	album_artist="${album_artist//Albumartist   /}"
-	album_artist="${album_artist//   : /}"
-	album_artist="${album_artist//[^[:alnum:][:space:].]/}"
-	album_artist="`echo $album_artist`"
-	while [[ "$album_artist" == *"  "* ]]; do
-		album_artist="${album_artist//  / }"
-	done
-	echo "*** Albumartist=$album_artist"
+	if [[ -z "$artist" && -z "$band" ]]; then
+		album_artist="`exiftool -Albumartist "$file"`"
+		album_artist="${album_artist//Albumartist   /}"
+		album_artist="${album_artist//   : /}"
+		album_artist="${album_artist//[^[:alnum:][:space:].]/}"
+		album_artist="`echo $album_artist`"
+		while [[ "$album_artist" == *"  "* ]]; do
+			album_artist="${album_artist//  / }"
+		done
+		echo "*** Albumartist=$album_artist"
+	fi
 
 	# Prefer Artist, then Band, then Albumartist
 	grandparent=""
-	if [[ -n $album ]]; then
+	if [[ -n $artist ]]; then
 		grandparent="$artist"
 	elif [[ -n $band ]]; then
 		grandparent="$band"