]> git.ktnx.net Git - mpd-feeder.git/blob - lib/App/MPD/Feeder/Command.pm
add list-unwanted-artists command
[mpd-feeder.git] / lib / App / MPD / Feeder / Command.pm
1 package App::MPD::Feeder::Command;
2
3 use strict;
4 use warnings;
5 use utf8;
6 use feature 'say';
7
8 use Log::Any qw($log);
9 use Object::Pad;
10
11 class App::MPD::Feeder::Command
12 isa App::MPD::Feeder {
13     method run(@args) {
14         my $cmd = shift @args;
15
16         if ( $cmd eq 'dump-config' ) {
17             die "dump-config command accepts no arguments\n" if @args;
18
19             $self->opt->dump;
20
21             return 0;
22         }
23
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) ) {
29                     $log->info(
30                         "Artist '$artist' added to the unwanted list\n");
31                 }
32                 else {
33                     $log->warn(
34                         "Artist '$artist' already in the unwanted list\n");
35                 }
36             }
37
38             return 0;
39         }
40
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) ) {
46                     $log->info(
47                         "Artist '$artist' deleted from the unwanted list\n");
48                 }
49                 else {
50                     $log->warn(
51                         "Artist '$artist' is not in the unwanted list\n");
52                 }
53             }
54
55             return 0;
56         }
57
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";
63
64             return 0;
65         }
66
67         if ( $cmd eq 'add-unwanted-album' ) {
68             die "NOT IMPLEMENTED\n";
69         }
70
71         if ( $cmd eq 'one-shot' ) {
72             die "one-shot command accepts no arguments\n" if @args;
73
74             $self->queue_songs( undef, sub {$self->mpd->loop->stop} );
75             $self->mpd->loop->run;
76             return 0;
77         }
78         elsif ( $cmd eq 'single' ) {
79             die "single command accepts no arguments\n" if @args;
80
81             $self->queue_songs( 1, sub {$self->mpd->loop->stop} );
82             $self->mpd->loop->run;
83             return 0;
84         }
85         else {
86             die "Unknown command '$cmd'";
87         }
88     }
89 }