Skip to content

Instantly share code, notes, and snippets.

@ggorlen
Last active December 7, 2020 00:11
Show Gist options
  • Select an option

  • Save ggorlen/bf5e70bcf551e1f8068add0698ab5d5a to your computer and use it in GitHub Desktop.

Select an option

Save ggorlen/bf5e70bcf551e1f8068add0698ab5d5a to your computer and use it in GitHub Desktop.
show bitrates of mp3s in a directory
# show bitrates of mp3s in a directory
use strict;
use warnings;
use feature 'say';
use File::Find;
use File::Spec::Functions;
use MP3::Info;
my @res;
sub walk {
if (-d $_) {
opendir(DIR, $_) or die "Could not open $_\n";
while (my $filename = readdir(DIR)) {
if ($filename =~ /\.mp3$/i) {
my $path = File::Spec::Functions::catfile($_, $filename);
my $info = get_mp3info($path);
push @res, [$info->{BITRATE}, $_];
last;
}
}
closedir(DIR);
}
}
find(\&walk, $ARGV[0] || ".");
@res = sort {$a->[0] <=> $b->[0]} @res;
for my $e (@res) {
say sprintf "%+3s :: %s", $e->[0], $e->[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment