Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created September 3, 2011 17:06
Show Gist options
  • Save tadzik/1191470 to your computer and use it in GitHub Desktop.
Save tadzik/1191470 to your computer and use it in GitHub Desktop.
Stupid mpd log analyzer
use MP3::Tag;
use perl5i::2;
# configuration, sorta
func bywhat($track) {
return $track->album->lc
}
my $descending = 0;
my $howmany = 40;
#####################
my %tracks;
# feed me mpd.log
# run me in your music directory, or I won't work
while (<>) {
next unless /player_thread: played/;
# yeah, unportable and shit
my $name = $_->substr(38, -2);
next unless $name ~~ /mp3$/i;
my $tag = MP3::Tag->new($name);
next unless $tag;
$tag->get_tags;
if (exists $tag->{'ID3v1'} or exists $tag->{'ID3v2'}) {
$tracks{bywhat($tag)}++;
} else {
carp "no metadata for '$name'";
}
}
my @list = sort { $tracks{$a} <=> $tracks{$b} } %tracks->keys;
@list = reverse @list if $descending;
for (@list[1..$howmany]) {
say $tracks{$_}, "\t", $_
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment