Posted: Sun Jun 20, 2010 2:33 pm Post subject: Perl recursive directory MP3 bitrate thing
Usage:
perl mp3bitrate.pl "X:\musik\supercoolband"
Also OK:
perl mp3bitrate.pl "X:/musik/supercoolband"
Also OK, but stupid:
perl mp3bitrate.pl "X:/musik\supercoolband"
Not OK!
perl mp3bitrate.pl "X:\musik\supercoolband\"
OK!
perl mp3bitrate.pl "X:\musik\supercoolband\\"
It will output something like this:
128 => 42
192 => 22
320 => 35
Average bitrate: 210.10101010101
Code:
use strict;
use warnings;
use MP3::Info;
my $dir = shift; #shift directory to recursively search for MP3s
my $filecount = 0; #number of MP3s found (and did not fail)
my $addrates = 0; #total bitrate of all files found
my $currate; #stores the current MP3's bitrate
my %bitrates; #counts the number of files with a specific bitrate (may replace $failcount)
process_files($dir);
sub process_files {
my $path = shift;
opendir (DIR, $path)
or die "Unable to open $path: $!";
my @files = grep { !/^\.{1,2}$/ } readdir (DIR);
closedir (DIR);
@files = map { $path . '/' . $_ } @files;
for (@files) {
if (-d $_) {
process_files ($_);
} else { if (($_ =~ m/([^.]+)$/)[0] eq 'mp3') {
if (my $mp3 = new MP3::Info $_)
{
$currate = $mp3->bitrate;
$bitrates{$currate}++;
}
else
{
$bitrates{'fail'}++;
print "Fail no. $bitrates{'fail'} on $_\n";
}
}
}
}
}
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum