From 6aec5b47880baa550b4a3860b1e1dbd3ace2c038 Mon Sep 17 00:00:00 2001 From: jq Date: Sat, 17 Mar 2007 13:53:53 +0000 Subject: [PATCH] [project @ 5631] list() method now splitted in the following Audio::MPD::Collection methods: - all_albums() - all_artists() - all_titles() - all_pathes() - albums_from_artist() --- lib/Audio/MPD.pm | 17 ------- lib/Audio/MPD/Collection.pm | 121 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 19 deletions(-) diff --git a/lib/Audio/MPD.pm b/lib/Audio/MPD.pm index fd4080b..1b60113 100644 --- a/lib/Audio/MPD.pm +++ b/lib/Audio/MPD.pm @@ -720,15 +720,6 @@ sub search { } -# -sub list { - my ($self, $type, $artist) = @_; - my $command = "list $type " . $type eq 'album' ? qq["$artist"] : ''; - return - map { /^[^:]+:\s+(.*)$/ ? $1 : () } - $self->_send_command( "$command\n" ); -} - # recursively, but only dirs & files sub listall { my ($self, $path) = @_; @@ -1249,14 +1240,6 @@ matching songs to the current playlist, instead of just returning information about them. -=item $mpd->list( $type, [$artist] ) - -Returns an array of all the "album" or "artist" in -the music database (as chosen by $type). $artist is an -optional parameter, which will only return albums by the -specified $artist when $type is "album". - - =item $mpd->listall( [$path] ) Return an array of all the songs in the music database. diff --git a/lib/Audio/MPD/Collection.pm b/lib/Audio/MPD/Collection.pm index db303f2..7dd399a 100644 --- a/lib/Audio/MPD/Collection.pm +++ b/lib/Audio/MPD/Collection.pm @@ -29,8 +29,19 @@ __PACKAGE__->mk_accessors( qw[ _mpd ] ); our ($VERSION) = '$Rev$' =~ /(\d+)/; +#-- +# Constructor + +# +# my $collection = Audio::MPD::Collection->new( $mpd ); # -# constructor. +# This will create the object, holding a back-reference to the Audio::MPD +# object itself (for communication purposes). But in order to play safe and +# to free the memory in time, this reference is weakened. +# +# Note that you're not supposed to call this constructor yourself, an +# Audio::MPD::Collection is automatically created for you during the creation +# of an Audio::MPD object. # sub new { my ($pkg, $mpd) = @_; @@ -40,6 +51,80 @@ sub new { return $self; } + +#-- +# Public methods + +# -- Collection: retrieving the whole collection + +# +# my @albums = $collection->all_albums; +# +# Return the list of all albums (strings) currently known by mpd. +# +sub all_albums { + my ($self) = @_; + return + map { /^Album: (.+)$/ ? $1 : () } + $self->_mpd->_send_command( "list album\n" ); +} + + +# +# my @artists = $collection->all_artists; +# +# Return the list of all artists (strings) currently known by mpd. +# +sub all_artists { + my ($self) = @_; + return + map { /^Artist: (.+)$/ ? $1 : () } + $self->_mpd->_send_command( "list artist\n" ); +} + + +# +# my @titles = $collection->all_titles; +# +# Return the list of all titles (strings) currently known by mpd. +# +sub all_titles { + my ($self) = @_; + return + map { /^Title: (.+)$/ ? $1 : () } + $self->_mpd->_send_command( "list title\n" ); +} + + +# +# my @pathes = $collection->all_pathes; +# +# Return the list of all pathes (strings) currently known by mpd. +# +sub all_pathes { + my ($self) = @_; + return + map { /^File: (.+)$/ ? $1 : () } + $self->_mpd->_send_command( "list filename\n" ); +} + + +# -- Collection: songs, albums & artists relations + +# +# my @albums = albums_from_artist($artist); +# +# Return all albums performed by $artist or where $artist participated. +# +sub albums_from_artist { + my ($self, $artist) = @_; + return + map { /^Album: (.+)$/ ? $1 : () } + $self->_mpd->_send_command( qq[list album "$artist"\n] ); +} + + + 1; __END__ @@ -81,10 +166,42 @@ of an C object. =back -=head2 +=head2 Retrieving the whole collection =over 4 +=item all_albums() + +Return the list of all albums (strings) currently known by mpd. + + +=item all_artists() + +Return the list of all artists (strings) currently known by mpd. + + +=item all_titles() + +Return the list of all song titles (strings) currently known by mpd. + + +=item all_pathes() + +Return the list of all pathes (strings) currently known by mpd. + + +=back + + +=head2 Songs, albums & artists relations + +=over 4 + +=item albums_from_artist( $artist ) + +Return all albums performed by $artist or where $artist participated. + + =back -- 2.11.4.GIT