Skip to content

Instantly share code, notes, and snippets.

@xavery
Created July 25, 2015 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavery/a9ead4c01e3b5404df58 to your computer and use it in GitHub Desktop.
Save xavery/a9ead4c01e3b5404df58 to your computer and use it in GitHub Desktop.
Script to generate a histogram showing the dominating years in your music collection
#!/usr/bin/perl
use warnings;
use strict;
use Audio::TagLib;
use File::Find;
use Statistics::Histogram;
die "Usage : $0 <dir>" unless $ARGV[0] && -d $ARGV[0];
sub unique
{
my %counts;
$counts{$_}++ for @{$_[0]};
return scalar(keys(%counts));
}
my @years;
sub wanted
{
return unless -f $_;
my $f = Audio::TagLib::FileRef->new($_);
if(defined($f->tag()))
{
my $year = $f->tag()->year();
push @years, $year if($year != 0);
}
}
find(\&wanted, $ARGV[0]);
print get_histogram(\@years, unique(\@years), 1, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment