1 package App::MPD::Feeder::Command;
6 use feature qw(fc say);
11 class App::MPD::Feeder::Command
12 isa App::MPD::Feeder {
14 my $cmd = shift @args;
16 if ( $cmd eq 'dump-config' ) {
17 die "dump-config command accepts no arguments\n" if @args;
24 if ( $cmd eq 'add-unwanted-artist' ) {
25 die "Missing command arguments\n" unless @args;
26 $self->set_db_needs_update(0);
27 for my $artist (@args) {
28 if ( $self->db->add_unwanted_artist($artist) ) {
30 "Artist '$artist' added to the unwanted list\n");
34 "Artist '$artist' already in the unwanted list\n");
41 if ( $cmd eq 'del-unwanted-artist' ) {
42 die "Missing command arguments\n" unless @args;
43 $self->set_db_needs_update(0);
44 for my $artist (@args) {
45 if ( $self->db->del_unwanted_artist($artist) ) {
47 "Artist '$artist' deleted from the unwanted list\n");
51 "Artist '$artist' is not in the unwanted list\n");
58 if ( $cmd eq 'list-unwanted-artists' ) {
59 die "This command has no arguments\n" if @args;
60 $self->set_db_needs_update(0);
61 my $count = $self->db->walk_unwanted_artists( sub { say @_ } );
62 say "Total unwanted artists: $count";
67 if ( $cmd eq 'add-unwanted-album' ) {
69 "Syntax: mpd-feeder add-unwanted-album «album name» by «artist name»\n"
70 unless @args == 3 and $args[1] =~ /^by$/i;
71 $self->set_db_needs_update(0);
72 my ( $album, $artist ) = @args[ 0, 2 ];
73 if ( $self->db->add_unwanted_album( $album, $artist ) ) {
75 "Album «$album» by «$artist» added to the unwanted list\n"
80 "Album «$album» by «$artist» already in the unwanted list\n"
87 if ( $cmd eq 'del-unwanted-album' ) {
89 "Syntax: mpd-feeder del-unwanted-album «album name» by «artist name»\n"
90 unless @args == 3 and $args[1] =~ /^by$/i;
91 $self->set_db_needs_update(0);
92 my ( $album, $artist ) = @args[ 0, 2 ];
93 if ( $self->db->del_unwanted_album( $album, $artist ) ) {
95 "Album «$album» by «$artist» deleted from the unwanted list\n"
100 "Album «$album» by «$artist» is not in the unwanted list\n"
107 if ( $cmd eq 'list-unwanted-albums' ) {
108 die "This command has no arguments\n" if @args;
109 $self->set_db_needs_update(0);
110 my $count = $self->db->walk_unwanted_albums(
111 sub ( $album, $artist ) { say "«$album» by «$artist»" } );
112 say "Total unwanted albums: $count";
117 if ( $cmd eq 'one-shot' ) {
118 die "one-shot command accepts no arguments\n" if @args;
120 $self->queue_songs( undef, sub {$self->mpd->loop->stop} );
121 $self->mpd->loop->run;
124 elsif ( $cmd eq 'single' ) {
125 die "single command accepts no arguments\n" if @args;
127 $self->queue_songs( 1, sub {$self->mpd->loop->stop} );
128 $self->mpd->loop->run;
132 die "Unknown command '$cmd'";