#!/bin/bash # # Move "Artist - Album" to "Artist - Year - Album" (requires "id3v2" and "gawk"). # Written by Agilo on April 2, 2006. # # Note: don't bluntly use this without testing/modifying; this was made for my personal use. # # For each dir which holds an mp3 file containing "01". for i in */*01*mp3 */*[cC][dD]1*/*01*mp3; do # Unset $SKIP (in case it's still set from the loop). unset SKIP; # Get the directory name. prog_dir=$(echo $i | gawk -F'/' '{print $1}'); # Skip Pink Floyd and Camel (because they already have the year date in the directory names). if [ "`echo $prog_dir | gawk -F' - ' '{print $1}'`" == "Pink Floyd" ] || [ "`echo $prog_dir | gawk -F' - ' '{print $1}'`" == "Camel" ] || [ "`echo $prog_dir | gawk -F' - ' '{print $1}'`" == "Yes" ]; then # Set $SKIP. SKIP="TRUE"; fi # If $SKIP is unset. if [ "$SKIP" != "TRUE" ]; then # Get the Year (this is a trivial way to do this, but it works..). prog_year=$(id3v2 -l "$i" | grep '(Year):' | gawk -F': ' '{print $2}'); # Get the Artist name from directory name. prog_artist=$(echo $prog_dir | gawk -F' - ' '{print $1}'); # Get the Album name from directory name. prog_album=$(echo $prog_dir | gawk -F' - ' '{print $2}'); # If there is an empty Year, skip the moving process and report it. if [ -z $prog_year ]; then echo -e "\n\nERROR, no \"Year\" found in: $prog_artist - $prog_album\n\n"; sleep 2; else # Prevent douplicates. if [ "$OLD_MOVE" != "$prog_artist - $prog_album" ]; then # Move the directory. echo "mv \"$prog_artist - $prog_album\" \"$prog_artist - $prog_year - $prog_album\""; #echo "$prog_artist - $prog_year - $prog_album" # Set variable to prevent douplicates. OLD_MOVE="$prog_artist - $prog_album"; fi fi fi done