]> git.ktnx.net Git - mpd-feeder.git/blob - bin/mpd-feeder
0203fae0502f84b3b22427e624120ec933270204
[mpd-feeder.git] / bin / mpd-feeder
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use utf8;
6
7 use App::MPD::Feeder;
8 use Log::Any qw($log);
9 use Log::Any::Adapter Stderr => log_level => 'error';
10
11 my $feeder = App::MPD::Feeder->new();
12
13 if (@ARGV) {
14     my $cmd = shift @ARGV;
15
16     if ($cmd eq 'dump-config') {
17         die "dump-config command accepts no arguments\n" if @ARGV;
18
19         $feeder->opt->dump;
20         exit;
21     }
22
23     if ( $cmd eq 'add-unwanted-artist' ) {
24         die "Missing command arguments\n" unless @ARGV;
25         $feeder->set_db_needs_update(0);
26         for my $artist (@ARGV) {
27             if ( $feeder->db_add_unwanted_artist($artist) ) {
28                 $log->info("Artist '$artist' added to the unwanted list\n");
29             }
30             else {
31                 $log->warn("Artist '$artist' already in the unwanted list\n");
32             }
33         }
34         exit;
35     }
36
37     if ( $cmd eq 'del-unwanted-artist' ) {
38         die "Missing command arguments\n" unless @ARGV;
39         $feeder->set_db_needs_update(0);
40         for my $artist (@ARGV) {
41             if ( $feeder->db_del_unwanted_artist($artist) ) {
42                 $log->info("Artist '$artist' deleted from the unwanted list\n");
43             }
44             else {
45                 $log->warn("Artist '$artist' is not in the unwanted list\n");
46             }
47         }
48         exit;
49     }
50
51     if ( $cmd eq 'add-unwanted-album' ) {
52         die "NOT IMPLEMENTED\n";
53     }
54
55     if ( $cmd eq 'one-shot' ) {
56         die "one-shot command accepts no arguments\n" if @ARGV;
57
58         $feeder->queue_songs(undef, sub { exit });
59         $feeder->mpd->loop->run;
60     }
61     elsif ( $cmd eq 'single' ) {
62         die "single command accepts no arguments\n" if @ARGV;
63
64         $feeder->queue_songs(1, sub { exit });
65         $feeder->mpd->loop->run;
66     }
67     else {
68         die "Unknown command '$cmd'";
69     }
70 }
71
72 $feeder->run_loop;