Created
September 3, 2011 17:06
-
-
Save tadzik/1191470 to your computer and use it in GitHub Desktop.
Stupid mpd log analyzer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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