diff options
Diffstat (limited to '.local/bin/splitart')
| -rwxr-xr-x | .local/bin/splitart | 32 | 
1 files changed, 32 insertions, 0 deletions
diff --git a/.local/bin/splitart b/.local/bin/splitart new file mode 100755 index 0000000..0beab28 --- /dev/null +++ b/.local/bin/splitart @@ -0,0 +1,32 @@ +#!/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  |