#!/bin/bash

if [ -z "$1" ]; then
    echo "Must provide artist name"
    exit 1
fi

ARTIST="$1"

# Use find to safely handle filenames with spaces and special characters
find . -maxdepth 1 -type f -name "*.mp3" | while IFS= read -r file; do
    # Extract filename without ./ prefix
    basefile="${file#./}"

    new_name=$(echo "$basefile" | sed -E "s/^$ARTIST - //; s/^${ARTIST}- //; s/$ARTIST//g")

    # Rename the file only if the new name is different
    if [[ "$basefile" != "$new_name" ]]; then
        mv -- "$basefile" "$new_name"
        echo "Renamed: '$basefile' → '$new_name'"
    fi
done
