From 4404a46e92de24d8f6db57109c62be71ffbd47be Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 12 Nov 2021 09:37:43 +0000 Subject: [PATCH] add list-unwanted-artists command --- lib/App/MPD/Feeder/Command.pm | 10 ++++++++++ lib/App/MPD/Feeder/DB.pm | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/App/MPD/Feeder/Command.pm b/lib/App/MPD/Feeder/Command.pm index 5c94a75..9a425be 100644 --- a/lib/App/MPD/Feeder/Command.pm +++ b/lib/App/MPD/Feeder/Command.pm @@ -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"; } diff --git a/lib/App/MPD/Feeder/DB.pm b/lib/App/MPD/Feeder/DB.pm index ce0bcdd..e38279a 100644 --- a/lib/App/MPD/Feeder/DB.pm +++ b/lib/App/MPD/Feeder/DB.pm @@ -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; -- 2.39.2