Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-23 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found