#!/bin/bash

# Define your root destination
DEST_BASE="/mnt/yggdrasil/media/music/sorted_music"

# Loop through all directories in the current location
for dir in */; do
    # Remove the trailing slash for cleaner paths
    folder_name="${dir%/}"
    
    # Check if the folder matches our expected "Artist - Album" pattern
    if [[ "$folder_name" == *" - "* ]]; then
        # Extract everything before the first " - "
        artist="${folder_name%% - *}"
        
        # Create the destination artist folder (does nothing if it already exists)
        mkdir -p "$DEST_BASE/$artist"
        
        # Move the folder into the new artist directory
        echo "Moving: '$folder_name'  ➔  '$DEST_BASE/$artist/'"
        mv "$folder_name" "$DEST_BASE/$artist/"
    else
        echo "Skipped: '$folder_name' (Does not match pattern)"
    fi
done

echo "Sorting complete!"
