#!/bin/bash # Script By Robert Navarro # crshman [at] gmail.com # # Rename/Moves MP3 files based on # id3v2 tags LIVE= # # Set to some value for live operation # ex # $LIVE=Yes # the script will move files around # # $LIVE= # the script won't move anything around PRE_DEST='/media/Data/Share/Music/' # Local directory to move files to for file in *.mp3; do if [ -e $file ]; then TRACK="`id3v2 -l "$file" | grep TRCK | awk '{ for (i=6;i<=NF;i++) { printf $i; printf " " } }'`" # Track Number SP_YEAR="`id3v2 -l "$file" | grep TYER | awk '{ for (i=3;i<=NF;i++) { printf $i; printf " " } }'`" YEAR=${SP_YEAR:0:$((${#SP_YEAR}-1))} # Track Year SP_ARTIST="`id3v2 -l "$file" | grep TPE1 | awk '{ for (i=4;i<=NF;i++) { printf $i; printf " " } }'`" ARTIST=${SP_ARTIST:0:$((${#SP_ARTIST}-1))} # Track Artist FIRST_ARTIST=${ARTIST:0:1} # First Letter of the Artist of the Track SP_ALBUM="`id3v2 -l "$file" | grep TALB | awk '{ for (i=4;i<=NF;i++) { printf $i; printf " " } }'`" ALBUM=${SP_ALBUM:0:$((${#SP_ALBUM}-1))} # Track Album SP_TITLE="`id3v2 -l "$file" | grep TIT2 | awk '{ for (i=4;i<=NF;i++) { printf $i; printf " " } }'`" TITLE=${SP_TITLE:0:$((${#SP_TITLE}-1))} # Track TITLE #Edit these to reflect your preferences FOLDER="$PRE_DEST$FIRST_ARTIST/$ARTIST/$ALBUM ($YEAR)" DEST="$FOLDER/$TRACK - $TITLE.mp3" #echo $file #echo $FOLDER #echo $DEST #echo -e "\n" if [ $LIVE ]; then mkdir -p "$FOLDER" mv "$file" "$DEST" fi fi done