#!/usr/bin/perl $dir='/home/joker/mp3incoming'; use MP3::Info; opendir(DIR, $dir) || die("couldn't open dir $dir: $!"); @files = sort grep { /\.mp3$/i } readdir(DIR); foreach $mp3 (@files) { $id3tags = get_mp3tag("${dir}/${mp3}"); $id3v2tags = get_mp3tag("${dir}/${mp3}", 2, 1); $title = $id3v2tags->{TIT2}; $artist = $id3v2tags->{TPE1}; if (! $title) { $title = $id3tags->{TITLE}; } if (! $artist) { $artist = $id3tags->{ARTIST}; } $newmp3 = "$artist - $title"; # remove some 'bad' characters $newmp3 =~ s/[\'\#\$\`\@\.\>\<\=\^\!\~]//g; # replace others with space $newmp3 =~ s/[\/\;\:\,\@]/\ /g; # remove tailing and heading spaces $newmp3 =~ s/^\s*//g; $newmp3 =~ s/\s*$//g; # compress whitespaces or use underline character # $newmp3 =~ s/\s+/\ /g; $newmp3 =~ s/\s+/\ /g; print "'$mp3' => '$newmp3.mp3'\n"; }