]> git.ktnx.net Git - mpd-feeder.git/blobdiff - lib/App/MPD/Feeder/Command.pm
implement unwanted album list manipulation
[mpd-feeder.git] / lib / App / MPD / Feeder / Command.pm
index 9a425be023bb419fc5952b7fb7fc7c22de0f3492..d2c4130a5691a9373d2db1ee35a90ad09bd30d77 100644 (file)
@@ -3,7 +3,7 @@ package App::MPD::Feeder::Command;
 use strict;
 use warnings;
 use utf8;
-use feature 'say';
+use feature qw(fc say);
 
 use Log::Any qw($log);
 use Object::Pad;
@@ -65,7 +65,53 @@ isa App::MPD::Feeder {
         }
 
         if ( $cmd eq 'add-unwanted-album' ) {
-            die "NOT IMPLEMENTED\n";
+            die
+                "Syntax: mpd-feeder add-unwanted-album «album name» by «artist name»\n"
+                unless @args == 3 and $args[1] =~ /^by$/i;
+            $self->set_db_needs_update(0);
+            my ( $album, $artist ) = @args[ 0, 2 ];
+            if ( $self->db->add_unwanted_album( $album, $artist ) ) {
+                $log->info(
+                    "Album «$album» by «$artist» added to the unwanted list\n"
+                );
+            }
+            else {
+                $log->warn(
+                    "Album «$album» by «$artist» already in the unwanted list\n"
+                );
+            }
+
+            return 0;
+        }
+
+        if ( $cmd eq 'del-unwanted-album' ) {
+            die
+                "Syntax: mpd-feeder del-unwanted-album «album name» by «artist name»\n"
+                unless @args == 3 and $args[1] =~ /^by$/i;
+            $self->set_db_needs_update(0);
+            my ( $album, $artist ) = @args[ 0, 2 ];
+            if ( $self->db->del_unwanted_album( $album, $artist ) ) {
+                $log->info(
+                    "Album «$album» by «$artist» deleted from the unwanted list\n"
+                );
+            }
+            else {
+                $log->warn(
+                    "Album «$album» by «$artist» is not in the unwanted list\n"
+                );
+            }
+
+            return 0;
+        }
+
+        if ( $cmd eq 'list-unwanted-albums' ) {
+            die "This command has no arguments\n" if @args;
+            $self->set_db_needs_update(0);
+            my $count = $self->db->walk_unwanted_albums(
+                sub ( $album, $artist ) { say "«$album» by «$artist»" } );
+            say "Total unwanted albums: $count";
+
+            return 0;
         }
 
         if ( $cmd eq 'one-shot' ) {