Apache-MP3
view release on metacpan or search on metacpan
MP3/Playlist.pm view on Meta::CPAN
-linebreak => 1,
-value => \@ok,
-labels => $descriptions),
submit(-name=>'Clear All',-value=>$self->x('Clear All')),
submit(-class=>'playlist',-name=>'Clear Selected',-value=>$self->x('Clear Selected')),
submit(-class=>'playlist',-name=>'Play Selected',-value=>$self->x('Play Selected')),
submit(-class=>'playlist',-name=>'Shuffle All',-value=>$self->x('Shuffle All')),
submit(-class=>'playlist',-name=>'Play All',-value=>$self->x('Play All')),
hidden(-name=>'playlist',-value=>1,-override=>1),
end_form(),
))
);
}
$self->SUPER::directory_bottom(@_);
}
sub control_buttons {
my $self = shift;
return (
$self->{possibly_truncated}
? ()
: (submit({-class=>'playlist',
-name=>'Add to Playlist',
-value=>$self->x('Add to Playlist')}),
submit({-class=>'playlist',
-name=>'Add All to Playlist',
-value=>$self->x('Add All to Playlist')
})
),
submit(-name=>'Play Selected',
-value=>$self->x('Play Selected')
),
submit(-name=>'Shuffle All',
-value=>$self->x('Shuffle All')
),
submit(-name=>'Play All',
-value=>$self->x('Play All'))
);
}
sub lookup_descriptions {
my $self = shift;
my $r = $self->r;
my %d;
for my $song (@_) {
next unless my $sub = $r->lookup_uri($song);
next unless my $file = $sub->filename;
next unless -r $file;
next unless my $info = $self->fetch_info($file,$sub->content_type);
$d{$song} = " $info->{description}";
}
return \%d;
}
sub directory_top {
my $self = shift;
$self->SUPER::directory_top(@_);
my @p = $self->playlist;
print div({-align=>'CENTER'},
a({-href=>'#playlist',-class=>'playlist'},$self->x('Playlist contains [quant,_1,song,songs].', scalar(@p))),br,
$self->{possibly_truncated} ? font({-color=>'red'},
strong($self->x('Your playlist is now full. No more songs can be added.'))) : '')
if @p;
}
sub playlist {
my $self = shift;
my @p = $self->{playlist} ? @{$self->{playlist}} : ();
$self->{playlist} = shift if @_;
return unless @p;
return wantarray ? @p : \@p;
}
1;
=head1 NAME
Apache::MP3::Playlist - Manage directories of MP3 files with sorting and persistent playlists
=head1 SYNOPSIS
# httpd.conf or srm.conf
AddType audio/mpeg mp3 MP3
# httpd.conf or access.conf
<Location /songs>
SetHandler perl-script
PerlHandler Apache::MP3::Playlist
PerlSetVar SortField Title
PerlSetVar Fields Title,Artist,Album,Duration
</Location>
=head1 DESCRIPTION
Apache::MP3::Playlist subclasses Apache::MP3::Sorted to allow the user
to build playlists across directories. Playlists are stored in
cookies and are persistent for the life of the browser. See
L<Apache::MP3> and L<Apache::MP3::Sorted> for details on installing
and using.
=head1 CUSTOMIZATION
The "playlist" class in the F<apache_mp3.css> cascading stylesheet
defines the color of the playlist area and associated buttons.
=head1 METHODS
Apache::MP3::Playlist overrides the following methods:
run(), directory_bottom(), control_buttons() and directory_top().
It adds several new methods:
=over 4
=item $result = $mp3->process_playlist
Process buttons that affect the playlist.
=item $hashref = $mp3->lookup_descriptions(@uris)
( run in 0.701 second using v1.01-cache-2.11-cpan-5735350b133 )