]> git.ktnx.net Git - mpd-feeder.git/blob - bin/mpd-feeder
99453c364981690263dc0bc53d3f73c265abd043
[mpd-feeder.git] / bin / mpd-feeder
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use utf8::all;
6
7 use App::MPD::Feeder;
8 use Log::Any qw($log);
9 use Log::Any::Adapter Stderr => log_level => 'error';
10
11 {   # autoflush without IO::Handle
12     my $fh = select STDERR;
13     $| = 1;
14     select $fh;
15 }
16
17 my $feeder = App::MPD::Feeder->new();
18
19 if (@ARGV) {
20     require App::MPD::Feeder::Command;
21     bless $feeder, 'App::MPD::Feeder::Command';
22
23     exit $feeder->run(@ARGV);
24 }
25
26 $feeder->run_loop;
27
28 __END__
29
30 =encoding UTF-8
31
32 =head1 NAME
33
34 mpd-feeder -- MPD playlist manager with emphasys on diversity
35
36 =head1 SYNOPSIS
37
38 Engage daemon mode, keeping the MPD playlist full:
39
40     mpd-feeder [I<option>...]
41
42 Perform a single command and return:
43
44     mpd-feeder [I<option>...] I<command>
45
46 =head1 DESCRIPTION
47
48 C<mpd-feeder> keeps the playlist of MPD full with songs, avoiding songs,
49 artists and albums that have been queued recently. This can be used for
50 listening to large song collections without repetitions that happen with random
51 shuffling or when a given artist has many more songs that the rest.
52
53 The song list is stored in a PostgreSQL database that is kept updated
54 automatically as the MPD database is updated.
55
56 The timespans for "recent" queueing are configurable.
57
58 =head1 COMMANDS
59
60 In daemon mode (with no command given), C<mpd-feeder> connects to MPD, updates
61 its local copy of the song database and makes sure that the playlist never has
62 fewer songs than the configured minimum. Playlist changes are detected when
63 they happen.
64
65 When a command is given, C<mpd-feeder> does not engage in daemon mode, but returns
66 to the OS after execution.
67
68 =head2 dump-config
69
70 Prints configuration file contents on standard output. Can be used to create
71 skeleton F<mpd-feeder.conf>. Makes no connection to MPD or PostgreSQL.
72
73 =head2 add-unwanted-artist I<artist name>
74
75 Adds one artist to toe list of unwanted artists. That list is consulted when a
76 new song needs to be added to MPD's playlist and songs by artists in it are
77 skipped.
78
79 =head2 del-unwanted-artist I<artist name>
80
81 The reverse of C<add-unwanted-artist>.
82
83 =head2 list-unwanted-artists
84
85 Prints the contents of the unwanted artist list, one per line.
86
87 =head2 add-unwanted-album I<album name> by I<artist name>
88
89 =head2 del-unwanted-album I<album name> by I<artist name>
90
91 =head2 list-unwanted-albums
92
93 Manupulate the list of unwanted albums. Useful when there is an album you don't
94 want to listen to, but you still want to hear other albums by the same artist.
95
96 =head2 one-shot
97
98 Connects to MPD, and if the playlist is below the configured minimum, adds some
99 songs.
100
101 =head2 single
102
103 Adds one song to the playlist. Ignores the configured minimum.
104
105 =head1 OPTIONS
106
107 =over
108
109 =item B<--log-level> I<trace|debug|info|notice|warning|error|critical|alert|emergency>
110
111 Set log verbosity. C<trace> is most talkative, including all exchanges with MPD.
112
113 =item B<--skip-db-update>
114
115 Skips the startup sync of the song database from MPD.
116
117 =item B<--tql> I<number>
118
119 =item B<--target-queue-length> I<number>
120
121 Sets the wanted playlist length.
122
123 =item B<--mpd-host> I<hostname>
124
125 =item B<--mpd-port> I<number>
126
127 Parameters for connecting to MPD.
128
129 =item B<--db-path> I<DSN>
130
131 =item B<--db-user> I<username>
132
133 Parameters for connecting to PostgreSQL.
134
135 =item B<--min-album-interval> I<duration>
136
137 =item B<--min-song-interval> I<duration>
138
139 =item B<--min-artist-interval> I<duration>
140
141 Tunes the minimum time between adding songs from the same album/artist and
142 before re-adding the same song.
143
144 I<duration> is a text duration, recognised by L<Time::Duration::Parse>.
145
146 =back
147
148 =head1 CONFIGURATION FILE
149
150 =head1 COPYRIGHT & LICENSE
151
152 Copyright © 2021 Damyan Ivanov L<dam+mpdfeeder@ktnx.net>
153
154 This program is free software; you can redistribute it and/or modify it under
155 the terms of the GNU General Public License version 2 as published by the Free
156 Software Foundation.
157
158 This program is distributed in the hope that it will be useful, but WITHOUT ANY
159 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
160 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
161
162 You should have received a copy of the GNU General Public License along with
163 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
164 Street, Fifth Floor, Boston, MA 02110-1301 USA.