my $rows = $mpd->send('listallinfo')->get;
+ $log->trace('got all songs from MPD');
+
$db->start_update;
try {
my $song_count;
$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;
}
$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 );
);
}
- method run {
-
- $self->prepare_to_wait_idle;
- }
-
method stop {
undef $mpd;
}
method run_loop {
+ $self->connect_mpd;
$self->connect_db;
for ( ;; ) {
- $self->queue_songs( undef, sub { $self->run } );
+ $self->queue_songs( undef, sub { $self->prepare_to_wait_idle } );
$log->debug("Entering event loop. PID=$$");