Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Perl recursive directory MP3 bitrate thing

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam
View previous topic :: View next topic  
Author Message
compactwater
I post too much
Reputation: 8

Joined: 02 Aug 2006
Posts: 3923

PostPosted: Sun Jun 20, 2010 2:33 pm    Post subject: Perl recursive directory MP3 bitrate thing Reply with quote

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";
                }
            }
        }
    }
}

foreach my $key (sort (keys(%bitrates))) {
   print "$key => $bitrates{$key}\n";
   if ($key eq 'fail') { last; }
   $addrates += $key * $bitrates{$key};
   $filecount += $bitrates{$key};
}
print "Average bitrate: " . ($addrates / $filecount);
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sun Jun 20, 2010 6:00 pm    Post subject: Reply with quote

Code:
[nathan@GLaDOS Desktop]$ perl m.pl ~/Music
Can't locate MP3/Info.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at m.pl line 3.
BEGIN failed--compilation aborted at m.pl line 3.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Random spam All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites