This is almost too easy. I recently ripped some of my CD's into MP3's with my favorite ripper/encoder, grip. I was so busy feeding it Radiohead CD after CD that i forgot to move the newly encoded MP3's to their final destination before the next batch was ripped/encoded. The end result was a directory structure similar to:

mp3
---radiohead
   ---100395
      ---01-you.mp3
   ---132557
      ---02-creep.mp3
   ---168860
      ---01-planet_telex.mp3
   (etc.)
   ---pablo_honey
   ---the_bends
Each MP3 file was stored in one of those '168860' directories and nothing was inside the directories that are actually named after the album titles. On top of that, i did not know offhand which album that '168860' belongs to. Normally i rip/encode one CD and then move the MP3's - now i have to move each file one at a time to it's proper album/directory and i have to manually look each one up by scanning the CD with my eyes/brain. Ughh ... that could take 30 minutes! (time better spent watching the Simpsons!)

The quick fix? First, move all MP3 files to inside the 'parent' directory (radiohead).


[jeffa@trinity radiohead]# mv */*.mp3 .
Second, run this script:
use MP3::Info; for my $file (<*.mp3>) { my $id3 = get_mp3tag($file); my $dir = lc $id3->{ALBUM}; $dir =~ tr/ /_/; system mv => $file => $dir; }
Much quicker. ;)

UPDATE: added Aristotle's improved alternative to backticks. Very nice. :) Oh, and as he says, this only works if your MP3's are properly tagged. Since they came straight from grip ... mine were. ;)

Also, i probably should have used zakzebrowski's suggestion, but it is trivial enough to change that i will leave the code untouched. (see his comment below).

OH YEAH: PodMaster says "CDex for yer win32"

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: Move MP3 files to proper dirs
by Aristotle (Chancellor) on Mar 11, 2003 at 03:03 UTC

    If they're properly tagged, that is. ;-(

    Btw:

    system mv => $file => $dir;

    Makeshifts last the longest.

Re: Move MP3 files to proper dirs
by Acolyte (Hermit) on Mar 11, 2003 at 18:37 UTC

    How about sorting by date/time stamp? If you at least know the order you ripped the CD's in and how many tracks each has you might be able to do a quick sort & move without having to visualy parse out the track names.

    Just a thought...

    Acolyte
    Studying at the feet of the masters
Re: Move MP3 files to proper dirs
by zakzebrowski (Curate) on Mar 13, 2003 at 12:23 UTC
    Why didn't you use File::Copy to advoid the system call?
    use File::Copy; #code removed move($file,$dir);


    ----
    Zak
    Pluralitas non est ponenda sine neccesitate - mysql's philosphy