X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=lib%2FApp%2FMPD%2FFeeder%2FCommand.pm;h=468e57fb20753c90937fb231f1ca21b76841d7b5;hb=c6856da18f274bf03ee7e8bb466bcba4db5eed79;hp=d2c4130a5691a9373d2db1ee35a90ad09bd30d77;hpb=cbce7ac600c7472872a0e4d042f2c8b4fdfefe6c;p=mpd-feeder.git diff --git a/lib/App/MPD/Feeder/Command.pm b/lib/App/MPD/Feeder/Command.pm index d2c4130..468e57f 100644 --- a/lib/App/MPD/Feeder/Command.pm +++ b/lib/App/MPD/Feeder/Command.pm @@ -1,135 +1,132 @@ -package App::MPD::Feeder::Command; - -use strict; -use warnings; +use v5.28; use utf8; -use feature qw(fc say); - -use Log::Any qw($log); -use Object::Pad; - +use Object::Pad 0.57; class App::MPD::Feeder::Command -isa App::MPD::Feeder { - method run(@args) { - my $cmd = shift @args; - - if ( $cmd eq 'dump-config' ) { - die "dump-config command accepts no arguments\n" if @args; - - $self->opt->dump; - - return 0; - } - - if ( $cmd eq 'add-unwanted-artist' ) { - die "Missing command arguments\n" unless @args; - $self->set_db_needs_update(0); - for my $artist (@args) { - if ( $self->db->add_unwanted_artist($artist) ) { - $log->info( - "Artist '$artist' added to the unwanted list\n"); - } - else { - $log->warn( - "Artist '$artist' already in the unwanted list\n"); - } - } + :isa(App::MPD::Feeder); - return 0; - } +use Log::Any qw($log); - if ( $cmd eq 'del-unwanted-artist' ) { - die "Missing command arguments\n" unless @args; - $self->set_db_needs_update(0); - for my $artist (@args) { - if ( $self->db->del_unwanted_artist($artist) ) { - $log->info( - "Artist '$artist' deleted from the unwanted list\n"); - } - else { - $log->warn( - "Artist '$artist' is not in the unwanted list\n"); - } - } +method run(@args) { + my $cmd = shift @args; - return 0; - } + if ( $cmd eq 'dump-config' ) { + die "dump-config command accepts no arguments\n" if @args; - 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"; + $self->opt->dump; - return 0; - } + return 0; + } - if ( $cmd eq 'add-unwanted-album' ) { - 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 ) ) { + if ( $cmd eq 'add-unwanted-artist' ) { + die "Missing command arguments\n" unless @args; + $self->set_db_needs_update(0); + for my $artist (@args) { + if ( $self->db->add_unwanted_artist($artist) ) { $log->info( - "Album «$album» by «$artist» added to the unwanted list\n" - ); + "Artist '$artist' added to the unwanted list\n"); } else { $log->warn( - "Album «$album» by «$artist» already in the unwanted list\n" - ); + "Artist '$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 ) ) { + return 0; + } + + if ( $cmd eq 'del-unwanted-artist' ) { + die "Missing command arguments\n" unless @args; + $self->set_db_needs_update(0); + for my $artist (@args) { + if ( $self->db->del_unwanted_artist($artist) ) { $log->info( - "Album «$album» by «$artist» deleted from the unwanted list\n" - ); + "Artist '$artist' deleted from the unwanted list\n"); } else { $log->warn( - "Album «$album» by «$artist» is not in the unwanted list\n" - ); + "Artist '$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; + } - 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"; - if ( $cmd eq 'one-shot' ) { - die "one-shot command accepts no arguments\n" if @args; + return 0; + } - $self->queue_songs( undef, sub {$self->mpd->loop->stop} ); - $self->mpd->loop->run; - return 0; + if ( $cmd eq 'add-unwanted-album' ) { + 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" + ); } - elsif ( $cmd eq 'single' ) { - die "single command accepts no arguments\n" if @args; - $self->queue_songs( 1, sub {$self->mpd->loop->stop} ); - $self->mpd->loop->run; - return 0; + 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 { - die "Unknown command '$cmd'"; + $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' ) { + die "one-shot command accepts no arguments\n" if @args; + + $self->queue_songs( undef, sub {$self->mpd->loop->stop} ); + $self->mpd->loop->run; + return 0; + } + elsif ( $cmd eq 'single' ) { + die "single command accepts no arguments\n" if @args; + + $self->queue_songs( 1, sub {$self->mpd->loop->stop} ); + $self->mpd->loop->run; + return 0; + } + else { + die "Unknown command '$cmd'"; } } + +1;