Subject: | mpd-rate and mpd-dynamic should fail gracefully when no song is playing |
I'm forwarding Debian bugs http://bugs.debian.org/cgi-bin/bugreport.cgi?
bug=655670 and http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=655669
When mpd's music collection is still empty, or there's no song currently
playing, mpd-rate and mpd-dynamic spew Perl warnings or even die with
messages that make no sense to non-Perl-programming users (see the bug
reports above for examples). The following patch attempts to fix this:
--- a/bin/mpd-rate
+++ b/bin/mpd-rate
@@ -24,7 +24,12 @@
use Getopt::Euclid qw{ :minimal_keys };
# fetch current song
-my $song = encode( 'utf-8', Audio::MPD->new->current->file );
+my $playing = Audio::MPD->new->current;
+unless (defined $playing)
+{
+ die "Cannot rate current song, as no song currently is playing!";
+}
+my $song = encode( 'utf-8', $playing->file );
# open ratings file
my %ratings;
--- a/bin/mpd-dynamic
+++ b/bin/mpd-dynamic
@@ -34,6 +34,8 @@
# fetch list of songs known by mpd.
my @files = $mpd->collection->all_pathes;
+die "Please set up mpd's audio collection before running mpd-dynamic"
+ unless @files;
while (1) { # endless loop
@@ -48,7 +50,7 @@
# yup - update playlist & song.
$playlist = $status->playlist;
- $song = $status->song;
+ $song = $status->song // 0;
# keep at most $ARGV{old} songs.
if ( $song > $ARGV{old} ) {
Florian