use MP3::Tag; use File::Find; use strict; require NameGen; my @fileList; my $debug = 1; my $testMode = 0; # Set this to 1 to NOT write any mp3 tags my $dir; if ($0=~m#^(.*)\\#) { $dir = "$1"; } elsif ($0=~m#^(.*)/# ) { $dir = "$1"; } else { `pwd` =~ /(.*)/; $dir = "$1"; } $dir =~ s/\\/\//g; find(\&matchMP3, $dir); print "Files found: ".($#fileList+1)."\n"; my $count = $#fileList+1; foreach my $item ( @fileList ) { print "Edit ID3: $item\n"; my ($title, $artist, $album, $year, $comment, $genre, $tracknum, $disc) = NameGen->getName($item); my $mp3 = MP3::Tag->new($item); $mp3->get_tags(); print "Removing ID3v1 tag...\n", if exists $mp3->{ID3v1}; $mp3->{ID3v1}->remove_tag, if exists $mp3->{ID3v1} and !$testMode; print "Removing ID3v2 tag...\n", if exists $mp3->{ID3v2}; $mp3->{ID3v2}->remove_tag, if exists $mp3->{ID3v2} and !$testMode; print "Creating new ID3v2 tag...\n"; my $tag = $mp3->new_tag("ID3v2"); print " Title_____$title\n", if $debug; print " Artist____$artist\n", if $debug; print " Album_____$album\n", if $debug; print " Year______$year\n", if $debug; print " Comment___$comment\n", if $debug; print " Genre_____$genre\n", if $debug; print " Track_____$tracknum\n", if $debug; print " Disc______$disc\n", if $debug; $tag->title($title); $tag->artist($artist); $tag->album($album); $tag->year($year); $tag->comment($comment, undef, "eng"); $tag->genre($genre); $tag->track($tracknum); $tag->add_frame("TPOS",$disc); #TPOS is Disc # $tag->write_tag(), if !$testMode; $mp3->close(); $count--; print "Done. (".($#fileList+1-$count)." of ".($#fileList+1).")\n\n"; } print "\nPress return to continue..."; my $pause = <>; exit; sub matchMP3() { print "Searching directory $File::Find::name...\n", if -d $File::Find::name; if ( -f $File::Find::name ) { if ( $File::Find::name =~ /\.mp3/ ) { print "Adding file ".($#fileList+1)." $File::Find::name\n", if $debug == 2; push (@fileList, $File::Find::name); } } }