]> git.ktnx.net Git - mpd-feeder.git/commitdiff
fix handling of database info
authorDamyan Ivanov <dmn@debian.org>
Thu, 11 Nov 2021 09:26:45 +0000 (09:26 +0000)
committerDamyan Ivanov <dmn@debian.org>
Thu, 11 Nov 2021 09:26:45 +0000 (09:26 +0000)
bin/mpd-feeder

index f0ed182eb3a56dda8c191aaff5a345266ad78a6f..3cc220668c996f3b500015e068c216c299a3d84d 100755 (executable)
@@ -236,26 +236,18 @@ SQL
         $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);