#!/usr/bin/perl use MP3::Tag; $noaction = 0; #$artist = "Rolling Stone Magazine"; $album = "Rolling Stone Magazine - Top 500 Songs"; $mp3dir = "E:/p2p2/done/music/Top 500 Songs - Rolling Stone Magazine/Top 500 Songs - Rolling Stone Magazine"; ### tmp for T500 ### @YOS = (); open( TC, "<$mp3dir/songlist.txt" ); while ( ) { /^\s*(\d+)\../; $tr = $1; /^\s*\d+\..+\((\d+)\)\s*$/; $yr = $1; # print "$tr - $yr\n" if $yr<1000; $YOS[$tr] = $yr; } close (TC); #################### opendir( DIR, $mp3dir ); @dir = readdir( DIR ); closedir( DIR ); open( LST, ">$mp3dir/filelist.txt" ); foreach ( @dir ) { $filepath = $mp3dir.'/'.$_; s/\r|\n//g; next if /^..?$/ || !/\.mp3$/; print "$filepath\n\t"; /^\s*(\d+)\s+-\s+(.+?)\s+-\s+(.+?)\s*\.mp3$/i; $track_NO = $1; $artist = $2; $songtitle = $3; $year = $YOS[$1]; $separator = ' '; @app = split( /$separator/, lc($songtitle)); for ( $i=0 ; $i<=$#app ; $i++ ) { $app[$i] = ucfirst($app[$i]) if length($app[$i])>1 || $i==0 || $app[$i] eq 'i'; } $songtitle = join ($separator, @app); print "Album $album\n\t"; print "Track # $track_NO\n\t"; print "Artist $artist\n\t"; print "Title $songtitle\n\t"; print "Year $year\n\t"; print LST "$track_NO - $artist - $songtitle ($year)\n"; $mp3 = MP3::Tag->new($filepath); $id3v1 = $mp3->new_tag("ID3v1"); $id3v2 = $mp3->new_tag("ID3v2"); if ( !$noaction ) { print STDERR "Erasing... "; if ( $id3v1->remove_tag() ) { print STDERR "OK!\n"; } else { print STDERR "EMPTY\n"; } print "\t"; $id3v1->song($songtitle); $id3v1->artist($artist); $id3v1->album($album); $id3v1->year($year) if $year; $id3v1->track($track_NO) if $track_NO; $id3v2->song($songtitle); $id3v2->artist($artist); $id3v2->album($album); # $id3v2->year($year) if $year; $id3v2->track($track_NO) if $track_NO; print "Writing... "; if ( $id3v1->write_tag() && $id3v2->write_tag() ) { print "OK!\n"; #$newnameWpath = $mp3dir.'/'."$track_NO - $songtitle.mp3"; #( $newname = "${songtitle}.mp3" ) =~ s/\//\\/g; #( $oldname = $filepath ) =~ s/\//\\/g; #print `rename \"$oldname\" \"$newname\"`; } else { print "ERROR!\n"; } } print "\n"; #$a = <> if $noaction; } close( LST ); print "Press Enter to exit.\n"; $asp = ;