Index: trunk/flactrack
===================================================================
--- trunk/flactrack	(revision 5)
+++ trunk/flactrack	(revision 10)
@@ -8,5 +8,5 @@
 
 use Getopt::Long qw{:config no_ignore_case};
-use File::Spec::Functions qw{catfile};
+use File::Spec::Functions qw{catfile splitpath};
 use File::Path;
 use Audio::FLAC::Header;
@@ -39,6 +39,15 @@
     #TODO: calculate TOC and DISCID from cuesheet if there is no MBZ_DISCID tag present
 
-    #TODO: also get the year from MBZ
     $info = get_musicbrainz_info($discid);
+
+    # if we have metadata, change the directory name to ARTIST.DATE.ALBUM, so it will sort nicely
+    my $base_dir = (splitpath($DIRECTORY))[1];
+    my $album_dir = join('.', map { to_filename($_) } @{$info}{qw{ALBUMARTISTSORT ORIGINALDATE ALBUM}});
+    # need to append "disc#" if this is a multidisc album
+    if ($info->{DISCTOTAL} > 1) {
+        $album_dir .= '.disc_' . $info->{DISCNUMBER};
+    }
+    $DIRECTORY = catfile($base_dir, $album_dir);
+    #die $DIRECTORY;
 }
 
@@ -112,4 +121,5 @@
     #TODO: deal with non-ascii characters (unidecode) e.g. ü --> ue
     return map {
+        s/&/ and /g;
         s/[^a-z0-9-_ ]+//gi;
         s/ +/_/g;
