]> git.ktnx.net Git - mpd-feeder.git/blob - lib/App/MPD/Feeder/Command.pm
split command execution into App::MPD::Feeder::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
7 use Log::Any qw($log);
8 use Object::Pad;
9
10 class App::MPD::Feeder::Command
11 isa App::MPD::Feeder {
12     method run(@args) {
13         my $cmd = shift @args;
14
15         if ( $cmd eq 'dump-config' ) {
16             die "dump-config command accepts no arguments\n" if @args;
17
18             $self->opt->dump;
19
20             return 0;
21         }
22
23         if ( $cmd eq 'add-unwanted-artist' ) {
24             die "Missing command arguments\n" unless @args;
25             $self->set_db_needs_update(0);
26             for my $artist (@args) {
27                 if ( $self->db_add_unwanted_artist($artist) ) {
28                     $log->info(
29                         "Artist '$artist' added to the unwanted list\n");
30                 }
31                 else {
32                     $log->warn(
33                         "Artist '$artist' already in the unwanted list\n");
34                 }
35             }
36
37             return 0;
38         }
39
40         if ( $cmd eq 'del-unwanted-artist' ) {
41             die "Missing command arguments\n" unless @args;
42             $self->set_db_needs_update(0);
43             for my $artist (@args) {
44                 if ( $self->db_del_unwanted_artist($artist) ) {
45                     $log->info(
46                         "Artist '$artist' deleted from the unwanted list\n");
47                 }
48                 else {
49                     $log->warn(
50                         "Artist '$artist' is not in the unwanted list\n");
51                 }
52             }
53
54             return 0;
55         }
56
57         if ( $cmd eq 'add-unwanted-album' ) {
58             die "NOT IMPLEMENTED\n";
59         }
60
61         if ( $cmd eq 'one-shot' ) {
62             die "one-shot command accepts no arguments\n" if @args;
63
64             $self->queue_songs( undef, sub {$self->mpd->loop->stop} );
65             $self->mpd->loop->run;
66             return 0;
67         }
68         elsif ( $cmd eq 'single' ) {
69             die "single command accepts no arguments\n" if @args;
70
71             $self->queue_songs( 1, sub {$self->mpd->loop->stop} );
72             $self->mpd->loop->run;
73             return 0;
74         }
75         else {
76             die "Unknown command '$cmd'";
77         }
78     }
79 }