]> git.ktnx.net Git - mpd-feeder.git/blobdiff - lib/App/MPD/Feeder.pm
no warnings on undef usage when idle waiting results in no changes
[mpd-feeder.git] / lib / App / MPD / Feeder.pm
index 3808c91f8195b36fc8983999e800d3f655999ce1..7da421a6433bbcc0a8f805cc8d103306200c7c0a 100644 (file)
@@ -132,6 +132,8 @@ use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
 
         my $rows = $mpd->send('listallinfo')->get;
 
+        $log->trace('got all songs from MPD');
+
         $db->start_update;
         try {
             my $song_count;
@@ -142,14 +144,20 @@ use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
                 $self->db->store_song( $entry->{file},
                     $entry->{AlbumArtist} // $entry->{Artist},
                     $entry->{Album} );
+
                 $song_count++;
             }
 
-            $log->info("Updated data about $song_count songs");
+            my ($total_songs, $total_artists, $total_albums,
+                $new_songs,   $new_artists,   $new_albums
+            ) = $self->db->finish_update;
 
-            $self->db->remove_stale_entries;
+            $log->info(
+                "Updated data about $song_count songs (including $new_songs new), "
+                    . "$total_artists artists (including $new_artists new) "
 
-            $self->db->finish_update;
+                    . "and $total_albums albums (including $new_albums new)"
+            );
 
             $db_needs_update = 0;
         }
@@ -166,7 +174,7 @@ use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
             $self->connect_mpd;
             $mpd->send('playlist')->on_done(
                 sub {
-                    my $present = scalar @{ $_[0] };
+                    my $present = scalar @{ $_[0] // [] };
 
                     $log->notice( "Playlist contains $present songs. Wanted: "
                             . $opt->target_queue_length );
@@ -229,14 +237,22 @@ use constant DEFAULT_CONFIG_FILE => '/etc/mpd-feeder/mpd-feeder.conf';
             sub {
                 my $result = shift;
 
-                if ( $result->{changed} eq 'database' ) {
+                undef $idler;
+
+                my $changed = $result->{changed} // '';
+
+                if ( $changed eq 'database' ) {
                     $db_needs_update = 1;
                     $self->prepare_to_wait_idle;
                 }
-                elsif ( $result->{changed} eq 'playlist' ) {
+                elsif ( $changed eq 'playlist' ) {
                     $self->queue_songs( undef,
                         sub { $self->prepare_to_wait_idle } );
                 }
+                elsif ( $changed eq '' ) {
+                    $log->debug("got no changes from idle");
+                    $self->prepare_to_wait_idle;
+                }
                 else {
                     use JSON;
                     $log->warn(