#!/bin/bash # Loop through all FLAC files in the current directory for file in *.flac; do # Extract the ARTIST tag from the FLAC file using metaflac artist=$(metaflac --show-tag=ARTIST "$file" | cut -d= -f2) # Check if the ARTIST tag contains common delimiters for multiple artists if [[ "$artist" == *"&"* ]] || [[ "$artist" == *","* ]] || [[ "$artist" == *"feat."* ]]; then # Replace '&' with ',' to treat both as the same delimiter artist=$(echo "$artist" | sed 's/&/,/g') # Split the ARTIST string by ',' into an array of artists IFS=',' read -r -a artists <<< "$artist" # Trim leading/trailing spaces from each artist name for i in "${!artists[@]}"; do artists[$i]=$(echo "${artists[$i]}" | xargs) # Trim spaces done # Remove the existing ARTIST tag metaflac --remove-tag=ARTIST "$file" # Add each artist as a separate ARTIST tag for artist_name in "${artists[@]}"; do echo "Setting ARTIST to '$artist_name' for file '$file'..." metaflac --set-tag=ARTIST="$artist_name" "$file" done else echo "No combined artists found for '$file', skipping..." fi done