Note: this was written for a <duck> windows computer, and is not directly portable without a few edits... I run it as a service under win2k. You can also run it from command-line with -d, it will just process once and quit.

Note 2: For them what don't know, eMusic.com is a great DRM-free mp3 service. Their jazz collection is huge. They just don't offer much customizability in the naming of files, and I like mine [artist - album] 01 songname.mp3" hence....

#!/usr/bin/perl # emusicfix.pl # # Will watch a specified folder for new MP3 files downloaded from emus +ic.com # and fix the filenames, then place them in their own directories by a +rtist. ################################################## # Dir where you want the artist directories created: my $basedir = "d:\\music\\"; # Dir where you will place newly-downloaded files: my $watch = "d:\\music\\em_save\\"; # Delimiter used by the filenames to separate artist, track etc.: my $delimiter = '-'; # Field orders: # The default is for names like: # Artist_Name-Album_Name-Track_Name-Song_Name.mp3 my %f = ( artist => 0, album => 1, track => 2, song => 3, ); # That's it! my $count = 0; my $debug = 0; if ($ARGV[0] =~ /-d/) { $debug = 1; processdir(); } else { daemonize(); } # You may want to consider running this as a service under win2k et al +. sub daemonize { while (1) { #run forever processdir(); sleep 20; } } sub processdir { my (@list); $count = 0; for (@list = sort `dir /b $watch\\*.mp3`) { chomp; fixfile($_) unless ($_ =~ /.*File Not Found.*/i); } if ($debug) { if ($count) { print "Moved $count files\n"} } } sub fixfile { my $filename = shift; chomp $filename; die "Bad infile" unless ($filename =~ /\.mp3$/); my (@file) = split/-/,$filename; for (@file) {$_ =~ s/_/ /g;} my $newfilename = '['.$file[$f{artist}].' - '.$file[$f{album}].'] +'.$file[$f{track}].' '.$file[$f{song}].''; $newfilename =~ s/ s /\'s /gi; $newfilename =~ s/ m /\'m /gi; my $source = $watch.$filename; my $dest = $basedir.$file[$f{artist}].'\\'.$newfilename; if (! makedir($basedir.$file[$f{artist}])) { print "Skipping file, can't make dir for $file[$f{artist}]" if + $debug; next; } if (! -e $dest) { my $result = `copy "$source" "$dest"`; if ($result =~ /1 file\(s\) copied\./) { $count++; print "$dest [OK]\n" if $debug; $del = `del "$watch$filename"`; print "Error deleting: $del\n" if ($del && $debug); }else{ print "Can't copy\n $source to\n $dest\n" if $debug; } } else { print "Skipping existing $filename\n" if $debug; } } sub makedir { my $dir = shift; if (-e $dir) { return 1; }else{ return mkdir $dir; } }

In reply to eMusic.com filename fixerupper by sedhed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.