Audio-DB
view release on metacpan or search on metacpan
DB/Reports.pm view on Meta::CPAN
my $album = $album_obj->album;
my $artist = $album_obj->artists;
my $year = $album_obj->years;
print join("\t",$album,$artist,$year),"\n";
=head1 OVERVIEW
Audio::DB::Reports facilitates several different classes of reports.
These include full library reports, song, artist, album, genre and
bitrate based reports. In general, each report returns arrays of the
appropriate objects.
Associated accessor methods are provide full access to the underlying
data.
=cut
#############################
# ALBUM REPORTS
#############################
=pod
=head2 Album Reports
Album reports aggregate songs into albums provide quick, decise views
of your collection. These include:
- listing all albums with associated artists and year released
- finding albums that fall below a given bitrate threshold
- finding albums with multiple bitrates
The following methods return a complex data structure. It is suggested
that you use provided methods to access the structure as it may change
in future releases.
=over 4
=item $report->album_list(@options);
Generate a list of all albums. Returns a list of Audio::DB::Album
objects, each potentially containing Audio::DB::Song objects.
Options:
-sort_order A sort key. One of artist, album, or year
-include_songs Boolean true to return songs with the albums
The resulting list can be sorted by artist, album, or year released by
passing the sort_order option. In the event that multiple years or
artists are contained on the album, the placeholder "Various Artists"
or "Various Years" will be used as the search key.
In the interests of memory consumption, the album_list() method
returns only the album name, artist, year, and bitrates for each album
by default. If you also need access to the song list for each
individual album, pass a true value with the -include_songs option.
=cut
# The internal data strcuture for album reports looks like this
#
# $self = [ {
# album => album name,
# album_id => album id,
# artists => [ all contributing artists ],
# songs => [ all contributing songs ],
# bitrates => [ bitrates seen for the album ],
# years => [ years seen for the album ],
# Also included in the hash ref but not necessarily accurate because of compilation CDs
# year => year released
# artist => primary artist
# } ]
#
sub album_list {
my ($self,@p) = @_;
my ($sort_by,$include) = rearrange([qw/SORT_BY INCLUDE/],@p);
my $albums = $self->fetch_class(-class=>'albums');
my %include = map {$_ => 1 } @$include;
if (defined $include{songs}) {
foreach my $album (@$albums) {
my $songs = $self->fetch(-class=>'song',-query=>$album->album_id,-perspective=>'by_album_id');
$album->add_songs($songs);
}
}
if ($sort_by) {
my @sorted = _sort_albums($sort_by,$albums);
return \@sorted;
}
return $albums;
}
=pod
=item $report->albums_with_multiple_bitrates(@options)
Display all albums that have songs of different bitrates. Returns a
list of Audio::DB::Album objects, each potentially containing
Audio::DB::Song objects.
Options:
-sort_order A sort key. One of artist, album, or year
-include_songs Boolean true to return songs with the albums
Like album_list(), returned albums can be sorted by passing the
sort_order option, and can contain songs if passed the -include_songs
option. See album_list() for details.
=cut
sub albums_with_multiple_bitrates {
my ($self,@p) = @_;
my ($sort_by) = rearrange([qw/SORT_BY/],@p);
my $adaptor = $self->adaptor;
my $albums = $self->fetch_class(-class=>'album');
foreach my $album (@$albums) {
my $songs = $self->fetch(-class=>'song',-query=>$album->album_id,-perspective=>'by_album_id');
( run in 2.094 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )