$self->connect_mpd;
$self->connect_db;
- $mpd->send('listallinfo')->on_done(
- sub {
- try {
- my $rows = shift;
- $db->begin_work;
+ my $rows = $mpd->send('listallinfo')->get;
+ try {
+ $db->begin_work;
- $db_generation++;
+ $db_generation++;
- my $song_count;
+ my $song_count;
- foreach my $entry (@$rows) {
- next unless exists $entry->{file};
- $self->db_store_song( $entry->{file},
- $entry->{Artist}, $entry->{Album} );
- $song_count++;
- }
+ foreach my $entry (@$rows) {
+ next unless exists $entry->{file};
+ $self->db_store_song( $entry->{file},
+ $entry->{Artist}, $entry->{Album} );
+ $song_count++;
+ }
- $log->info("Updated data about $song_count songs");
+ $log->info("Updated data about $song_count songs");
- $self->db_remove_stale_entries;
+ $self->db_remove_stale_entries;
- $self->db_set_option( generation => $db_generation );
+ $self->db_set_option( generation => $db_generation );
- $db->commit;
- }
- catch {
- my $err = $@;
+ $db->commit;
+ }
+ catch {
+ my $err = $@;
- $db_generation--;
+ $db_generation--;
- $db->rollback;
+ $db->rollback;
- die $err;
- }
- }
- );
+ die $err;
+ }
}
method db_find_suitable_songs($num) {