Got a lot of untagged and dirty MP3s? First sort them according to ARTIST and ALBUM into a 2-level directory structure under directory mp3:

Directory tree

mp3
 +John Doe
  +Debut
   +Track1.mp3
   +Track2.mp3
   +Track3.mp3
  +OtherAlbum
   +Track1.mp3
   +Track2.mp3
 +Jane Dae
etc.
Then do the magic script:

Code: tag_mp3s.sh

#!/bin/bash

MP3DIR=mp3

# tags artist and album tag of all mp3s in album directories (second level) based on level1-dirname and level2-dirname

( cd $MP3DIR ; for ARTIST in *; do 
  ( if test -d "$ARTIST"; then cd  "$ARTIST" ; echo "$ARTIST #############"; for ALBUM in *; do 
    ( if test -d "$ALBUM"; then cd "$ALBUM"; echo "$ALBUM -------------"; for TRACK in *.mp3; do
      echo -n ;
      # id3info "$TRACK"
      id3tag --artist "$ARTIST" --album "$ALBUM" "$TRACK"
    done ; fi ) ;     
  done ; fi )  ; 
done )

# tags artist of all mp3s in artist directories (first level) based on level1-dirname

( cd $MP3DIR ; for ARTIST in *; do 
  ( if test -d "$ARTIST"; then cd  "$ARTIST" ; echo "$ARTIST #############"; for TRACK in *.mp3; do 
    ( if test -f "$TRACK"; then 
        echo -n ;
        # id3info "$TRACK"
        id3tag --artist "$ARTIST" "$TRACK"
      fi ) ;     
  done ; fi )  ; 
done )

The script takes the names of the level-1 directory and level-2 directory for tagging.

Attention! Your old tags will be overwritten (actually only the ARTIST and ALBUM parts).