#!/usr/bin/perl -w
use strict;
print "Enter the <dir> where the mp3's are found: ";
chomp (my $dir = <stdin>);
chdir($dir) or die "Canot change $dir :$!\n";
opendir(DIR,".") or die "Cannot open $dir:$!\n";
my @songs=grep(/\.mp3$/i,readdir(DIR));
closedir(DIR);
foreach(@songs)
{
my @id = id3check($_);
if($id[0] && $id[1])
{
rename $_,"$id[0] - $id[1].mp3" or print "$_ : $!\n"; next;
print "$id[0] - $id[1].mp3\n";
}
elsif($_ =~ m/(\s*[^-]*)-\s*([^.]*).mp3/i)
{
$id[0] = $1;
$id[1] = $2;
s/\s*$|^\s*|{|}//g for ($id[0],$id[1]);
rename $_,"$id[0] - $id[1].mp3";
print "$id[0] - $id[1].mp3\n";
}
else
{
print "Couldn't rename $_\n";
}
}
sub id3check
{
open(SONG, "<$_[0]");
my $tag;
my @id;
binmode SONG;
seek SONG,-128,2;
read SONG,$tag,3;
if($tag eq "TAG")
{
read(SONG,$id[1],30);
read(SONG,$id[0],30);
s/\s*$|{|}//g for ($id[0],$id[1]);
return @id;
}
close(SONG);
}
</pre><p>
nope
(This post was edited by Jasmine on Jan 11, 2001, 5:32 PM)