3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 Readonly
my $OLD => 10; # number of old songs to keep
29 Readonly
my $NEW => 10; # number of new songs to have at every moment
30 Readonly
my $SLEEP => 5; # time to sleep before checking for changes
38 my $mpd = Audio
::MPD
->new;
40 # fetch list of songs known by mpd.
41 my @files = $mpd->collection->all_pathes;
44 while (1) { # endless loop
46 eval { $status = $mpd->status };
49 if ( $status->playlist > $playlist
50 || defined $status->song && $status->song != $song ) {
51 # playlist and/or current song has changed
52 $playlist = $status->playlist;
53 $song = $status->song;
61 exit; # should not be there...
66 # keep at most $OLD songs.
68 my $old = $song - $OLD;
69 $mpd->delete(0) for 1..$old;
72 # add at most $NEW songs.
73 my $pl = $mpd->playlist;
74 if ( $#$pl - $song < $NEW ) {
75 my $new = $NEW - ( $#$pl - $song );
76 $mpd->add( $files[ rand @files ] ) for 1..$new;
86 mpd-dynamic - a dynamic playlist for mpd
96 this program implements a dynamic playlist for mpd.
98 MPD (music player daemon) is a cool music player, but it lacks a dynamic
99 playlist. A dynamic playlist is a playlist that will change automatically
102 In particular, it will remove already played songs (keeping at most a given
103 number) and add new songs to the playlist so it never fall short of songs.
105 C<mpd-dynamic> is a low-resource program.
107 Note that since mpd is a daemon needing no gui to work, C<mpd-dynamic> is
108 also a daemon. That is, it will fork and do all its work from the background.
109 This way, you can fire C<mpd> and C<mpd-dynamic> and forget completely
110 about your music: it will just be there! :-)
115 Jerome Quelin <jquelin@cpan.org>
120 Copyright (c) 2007 Jerome Quelin <jquelin@cpan.org>
122 This program is free software; you can redistribute it and/or
123 modify it under the same terms as Perl itself.