From e71640afae22ad6a37e601cd0e805da5c25d6aaa Mon Sep 17 00:00:00 2001 From: jq Date: Sat, 17 Mar 2007 14:20:19 +0000 Subject: [PATCH] [project @ 5634] lsinfo() renamed in AM::Collection::items_in_dir() --- lib/Audio/MPD.pm | 30 ------------------------------ lib/Audio/MPD/Collection.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lib/Audio/MPD.pm b/lib/Audio/MPD.pm index 23b34c6..d40f451 100644 --- a/lib/Audio/MPD.pm +++ b/lib/Audio/MPD.pm @@ -720,29 +720,6 @@ sub search { } -# only in the current path, all tags -sub lsinfo { - my ($self, $path) = @_; - $path ||= ''; - - my @lines = $self->_send_command( qq[lsinfo "$path"\n] ); - - my @results; - my %element; - foreach my $line (@lines) { - chomp $line; - next unless $line =~ /^([^:]+):\s(.+)$/; - if ($1 eq 'file' || $1 eq 'playlist' || $1 eq 'directory') { - push @results, { %element } if %element; - %element = (); - } - $element{$1} = $2; - } - push @results, { %element }; - return @results; - # FIXME: return item::songs / item::directory -} - ############################################################### # CUSTOM METHODS # @@ -1210,13 +1187,6 @@ matching songs to the current playlist, instead of just returning information about them. - -=item $mpd->lsinfo( [$directory] ) - -Returns an array of hashes containing all the paths and metadata about -songs in the specified directory. If no directory is specified, then only -the songs/directories in the root directory are listed. - =back diff --git a/lib/Audio/MPD/Collection.pm b/lib/Audio/MPD/Collection.pm index 9ae1aa8..86830a2 100644 --- a/lib/Audio/MPD/Collection.pm +++ b/lib/Audio/MPD/Collection.pm @@ -125,6 +125,38 @@ sub all_items_simple { } +# +# my @items = $collection->items_in_dir( [$path] ); +# +# Return the items in the given $path. If no $path supplied, do it on mpd's +# root directory. +# +# Note that this sub does not work recusrively on all directories. +# +sub items_in_dir { + my ($self, $path) = @_; + $path ||= ''; + + my @lines = $self->_send_command( qq[lsinfo "$path"\n] ); + my (@list, %param); + + # parse lines in reverse order since "file:" comes first. + # therefore, let's first store every other parameter, and + # the "file:" line will trigger the object creation. + # of course, since we want to preserve the playlist order, + # this means that we're going to unshift the objects. + foreach my $line (reverse @lines) { + next unless $line =~ /^([^:]+):\s+(.+)$/; + $param{$1} = $2; + next unless $1 eq 'file' || $1 eq 'directory'; # last param of item + unshift @list, Audio::MPD::Item->new(%param); + %param = (); + } + return @list; +} + + + # -- Collection: retrieving the whole collection # @@ -262,6 +294,14 @@ tag file filled. Any other tag will be empty, so don't use this sub for any other thing than a quick scan! +=item items_in_dir( [$path] ) + +Return the items in the given C<$path>. If no C<$path> supplied, do it on +mpd's root directory. + +Note that this sub does not work recusrively on all directories. + + =back -- 2.11.4.GIT