X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=bin%2Fmpd-feeder;h=29a6d5b10f6247f2bf6e9ee54e65ae96f8e16605;hb=7bcfd7b37974fc1ce0fa6020117a6320f8451bfc;hp=0203fae0502f84b3b22427e624120ec933270204;hpb=b917752b4de5f4d073d90c3cb83fb4f61ce630da;p=mpd-feeder.git diff --git a/bin/mpd-feeder b/bin/mpd-feeder index 0203fae..29a6d5b 100755 --- a/bin/mpd-feeder +++ b/bin/mpd-feeder @@ -2,71 +2,25 @@ use strict; use warnings; -use utf8; +use utf8::all; use App::MPD::Feeder; use Log::Any qw($log); use Log::Any::Adapter Stderr => log_level => 'error'; +{ # autoflush without IO::Handle + my $fh = select STDERR; + $| = 1; + select $fh; +} + my $feeder = App::MPD::Feeder->new(); if (@ARGV) { - my $cmd = shift @ARGV; - - if ($cmd eq 'dump-config') { - die "dump-config command accepts no arguments\n" if @ARGV; - - $feeder->opt->dump; - exit; - } - - if ( $cmd eq 'add-unwanted-artist' ) { - die "Missing command arguments\n" unless @ARGV; - $feeder->set_db_needs_update(0); - for my $artist (@ARGV) { - if ( $feeder->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"); - } - } - exit; - } - - if ( $cmd eq 'del-unwanted-artist' ) { - die "Missing command arguments\n" unless @ARGV; - $feeder->set_db_needs_update(0); - for my $artist (@ARGV) { - if ( $feeder->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"); - } - } - exit; - } - - if ( $cmd eq 'add-unwanted-album' ) { - die "NOT IMPLEMENTED\n"; - } - - if ( $cmd eq 'one-shot' ) { - die "one-shot command accepts no arguments\n" if @ARGV; - - $feeder->queue_songs(undef, sub { exit }); - $feeder->mpd->loop->run; - } - elsif ( $cmd eq 'single' ) { - die "single command accepts no arguments\n" if @ARGV; + require App::MPD::Feeder::Command; + bless $feeder, 'App::MPD::Feeder::Command'; - $feeder->queue_songs(1, sub { exit }); - $feeder->mpd->loop->run; - } - else { - die "Unknown command '$cmd'"; - } + exit $feeder->run(@ARGV); } $feeder->run_loop;