$mpd->send('listallinfo')->on_done(
sub {
try {
- $db->begin;
+ my $rows = shift;
+ $db->begin_work;
$db_generation++;
- my ($song, $artist, $album);
-
- foreach my $row (@_) {
- chomp($row);
-
- if ($row =~ s/^file:\s*//) {
- $self->db_store_song( $song, $artist, $album );
- $song = $row;
- $artist = $album = undef;
- }
- elsif ( $row =~ s/^Artist:\s*// ) {
- $artist = $row;
- }
- elsif ( $row =~ s/^Album:\s*// ) {
- $album = $row;
- }
+ my $song_count;
+
+ foreach my $entry (@$rows) {
+ next unless exists $entry->{file};
+ $self->db_store_song( $entry->{file},
+ $entry->{Artist}, $entry->{Album} );
+ $song_count++;
}
$self->db_store_song($song, $artist, $album);