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
23 use Getopt
::Euclid qw
[ :minimal_keys
];
25 use Time
::HiRes qw
[ usleep
];
27 Proc
::Daemon
::Init
unless $ARGV{debug
};
30 my $song = 0; # song currently playing
31 my $playlist = 0; # playlist version
32 my $mpd = Audio
::MPD
->new;
34 # fetch list of songs known by mpd.
35 my @files = $mpd->collection->all_pathes;
38 while (1) { # endless loop
40 eval { $status = $mpd->status };
41 next if $@
; # error while peaking status
43 # do playlist and/or current song have changed?
44 next unless $status->playlist > $playlist
45 || defined $status->song && $status->song != $song;
48 # yup - update playlist & song.
49 $playlist = $status->playlist;
50 $song = $status->song;
52 # keep at most $ARGV{old} songs.
53 if ( $song > $ARGV{old
} ) {
54 my $old = $song - $ARGV{old
};
55 eval { $mpd->delete(0) for 1..$old };
58 # add at most $ARGV{new} songs.
59 my $pl = $mpd->playlist;
60 if ( $#$pl - $song < $ARGV{new} ) {
61 my $new = $ARGV{new
} - ( $#$pl - $song );
62 eval { $mpd->add( $files[ rand @files ] ) for 1..$new };
66 usleep
$ARGV{sleep} * 1000 * 1000;
69 exit; # should not be there...
77 mpd-dynamic - a dynamic playlist for mpd
87 This is mpd-dynamic version 0.2
92 This program implements a dynamic playlist for mpd.
94 MPD (music player daemon) is a cool music player, but it lacks a dynamic
95 playlist. A dynamic playlist is a playlist that will change automatically
98 In particular, it will remove already played songs (keeping at most a given
99 number) and add new songs to the playlist so it never fall short of songs.
101 Note that since mpd is a daemon needing no gui to work, C<mpd-dynamic> is
102 also a daemon. That is, it will fork and do all its work from the background.
103 This way, you can fire C<mpd> and C<mpd-dynamic> and forget completely
104 about your music (especially since C<mpd-dynamic> is a low-resource program):
105 it will just be there! :-)
112 Path of configuration file. Defaults to C<~/.mpd/mpd-dynamic.conf>.
116 file.default: "$ENV{HOME}/.mpd/mpd-dynamic.conf"
121 Number of old tracks to keep in the backlog. Defaults to 10.
124 old.type: integer >= 0
130 Number of new tracks to keep in the to-be-played playlist. Defaults to 10.
133 new.type: integer > 0
137 =item -s[leep] <sleep>
139 Time spent sleeping (in seconds) before checking if playlist should be updated.
142 sleep.type: number > 0
148 Run mpd-dynamic in debug mode. In particular, the program will not daemonize
154 Jerome Quelin <jquelin@cpan.org>
159 Copyright (c) 2007 Jerome Quelin <jquelin@cpan.org>
161 This program is free software; you can redistribute it and/or
162 modify it under the same terms as Perl itself.