i personally like my mp3 files named a particular way. it drives me nuts if they aren't named this way. i've also got them wonderfully organized in my filesystem, but that's another story.
what i have here is a script that i drag a folder full of mp3's on to (it's on my desktop right now), and it will rename all of the files to my liking.
the format is: ## - <Artist> - <Song Name>.mp3 (where ## is a two digit track number).
so here it is... i haven't modified it in a bit, so it could probably be optomized, improved... but it's currently working, and i have other things to do, so it'll stay as is for now.
#!/usr/bin/perl
use strict;
use MP3::Info;
my $folder = $ARGV[0];
if ( $folder eq "" ) {
print "You suck\n"; # or any other kind error message!
exit;
}
opendir( DIR, $folder );
my @files = map { $folder . "\\" . $_ } readdir( DIR );
closedir( DIR );
open FILE, ">", "debug.txt";
foreach ( @files ) {
my $mp3 = new MP3::Info( $_ ) or next;
my $new_name =
( $mp3->tracknum ne "" ? sprintf( "%02d", $mp3->tracknum ) . "
+ - " : "" )
. $mp3->artist . " - "
. $mp3->title . ".mp3";
$new_name =~ s/[\/:?]//g; # take out illegal characters
$new_name = $folder . "\\" . $new_name;
print $new_name, "\n";
print FILE "$_ -> $new_name\n";
rename $_, $new_name;
}
close FILE;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.