]> git.ktnx.net Git - mpd-feeder.git/commitdiff
add list-unwanted-artists command
authorDamyan Ivanov <dmn@debian.org>
Fri, 12 Nov 2021 09:37:43 +0000 (09:37 +0000)
committerDamyan Ivanov <dmn@debian.org>
Fri, 12 Nov 2021 09:37:43 +0000 (09:37 +0000)
lib/App/MPD/Feeder/Command.pm
lib/App/MPD/Feeder/DB.pm

index 5c94a756ceef25e26375a6adb9f2a98405147f94..9a425be023bb419fc5952b7fb7fc7c22de0f3492 100644 (file)
@@ -3,6 +3,7 @@ package App::MPD::Feeder::Command;
 use strict;
 use warnings;
 use utf8;
+use feature 'say';
 
 use Log::Any qw($log);
 use Object::Pad;
@@ -54,6 +55,15 @@ isa App::MPD::Feeder {
             return 0;
         }
 
+        if ( $cmd eq 'list-unwanted-artists' ) {
+            die "This command has no arguments\n" if @args;
+            $self->set_db_needs_update(0);
+            my $count = $self->db->walk_unwanted_artists( sub { say @_ } );
+            say "Total unwanted artists: $count";
+
+            return 0;
+        }
+
         if ( $cmd eq 'add-unwanted-album' ) {
             die "NOT IMPLEMENTED\n";
         }
index ce0bcdd643f3c18ac02f974ef073bc92ccb4cd0f..e38279a127c4dd53c3892bf8711b4ccb1edb993c 100644 (file)
@@ -261,6 +261,23 @@ SQL
         $log->debug("DB generation is $generation");
     }
 
+    method walk_unwanted_artists($callback) {
+        $self->connect;
+
+        my $count = 0;
+
+        my $sth = $db->prepare('SELECT artist FROM unwanted_artists ORDER BY 1');
+        my $artist;
+        $sth->execute;
+        $sth->bind_columns(\$artist);
+        while ( $sth->fetchrow_arrayref ) {
+            $count++;
+            $callback->($artist);
+        }
+
+        return $count;
+    }
+
     method disconnect {
         return unless $db;