]> git.ktnx.net Git - mpd-feeder.git/blob - bin/mpd-feeder
fix license statement
[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 to the OS:
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 (but see C<--skip-db-update> option below)
62 and makes sure that the playlist is never left with fewer songs than the
63 configured minimum. Playlist changes are detected when they happen.
64
65 When a command is given, C<mpd-feeder> does not engage in daemon mode, but
66 returns 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 a specific album
94 you don't want to listen to, but you don't mind other albums by the same
95 artist.
96
97 =head2 one-shot
98
99 Connects to MPD, and if the playlist is below the configured minimum, adds some
100 songs.
101
102 =head2 single
103
104 Adds one song to the playlist. Ignores the configured minimum playlist length.
105
106 =head1 OPTIONS
107
108 =over
109
110 =item B<--config> I<file>
111
112 =item B<--cfg> I<file>
113
114 The configuration file to read at startup.
115
116 B<Default>: C</etc/mpd-feeder/mpd-feeder.conf>.
117
118 =item B<--log-level> I<trace|debug|info|notice|warning|error|critical|alert|emergency>
119
120 Set log verbosity. C<trace> is most talkative, including all exchanges with MPD.
121
122 =item B<--skip-db-update>
123
124 Skips the startup sync of the song database from MPD.
125
126 =item B<--tql> I<number>
127
128 =item B<--target-queue-length> I<number>
129
130 Sets the wanted playlist length.
131
132 =item B<--mpd-host> I<hostname>
133
134 =item B<--mpd-port> I<number>
135
136 Parameters for connecting to MPD.
137
138 =item B<--db-path> I<DSN>
139
140 =item B<--db-user> I<username>
141
142 Parameters for connecting to PostgreSQL.
143
144 =item B<--min-album-interval> I<duration>
145
146 =item B<--min-song-interval> I<duration>
147
148 =item B<--min-artist-interval> I<duration>
149
150 Tunes the minimum time between adding songs from the same album/artist and
151 before re-adding the same song.
152
153 I<duration> is a text duration, recognised by L<Time::Duration::Parse>.
154
155 =back
156
157 =head1 CONFIGURATION FILE
158
159 Configuration file is an C<.ini> file with the following sections. You can get
160 a skeleton configuration by executing C<mpd-feeder dump-config>. That will
161 produce a configuration file filled with the default values.
162
163 =head2 [mpd-feeder]
164
165 =over
166
167 =item B<log_level> = I<level>
168
169 Determines the verboseness of the logging. See L</--log-level> option above.
170
171 B<Default>: C<warn>.
172
173 =back
174
175 =head2 [mpd]
176
177 =over
178
179 =item B<host> = I<hostname>
180
181 The host where MPD is running.
182
183 B<Default>: none. However, L<Net::Async::MPD> defaults to the value of the
184 C<MPD_HOST> environment variable, and if that is empty - C<localhost>.
185
186 =item B<port> = I<number>
187
188 The port number where MPD is listening.
189
190 B<Default>: none. However, L<Net::Async::MPD> defaults to the value of the
191 C<MPD_PORT> environment variable, and if that is empty - C<6600>.
192
193 =item B<initial-reconnect-delay> = I<duration>
194
195 =item B<max-reconnect-delay> = I<duration>
196
197 When the connection to MPD is lost, a delay is inserted before a re-connection
198 attempt is made. The duration of the delay is controlled with these two
199 options. Each delay is a bit longer than the last, starting with the value of
200 <initial-reconnect-delay>, and topped at the value of C<max-reconnect-delay>.
201
202 When a connection is made, the delay before the next re-connection is reset to
203 C<initial-reconnect-delay>.
204
205 B<Default>: C<3 seconds> for C<initial-reconnect-delay> and C<2 minutes> for
206 C<max-reconnect-delay>.
207
208 =back
209
210 =head2 [queue]
211
212 =over
213
214 =item B<target-length> = I<number>
215
216 The number of songs to always have in the MPD's playlist.
217
218 B<Default>: C<10>.
219
220 =item B<min-song-interval> = I<duration>
221
222 The minimum amount of time after a song is added to the playlist by
223 B<mpd-feeder>, before it is considered again.
224
225 B<Default>: C<13 days>
226
227 =item B<min-album-interval> = I<duration>
228
229 The minimum amount of time after a song is added to the playlist by
230 B<mpd-feeder> before songs from the same album are considered for addition to
231 the playlist.
232
233 B<Default>: C<5 hours>.
234
235 =item B<min-artist-interval> = I<duration>
236
237 The minimum amount of time after a song is added to the playlist by
238 B<mpd-feeder> before songs by the same artist are consideret for addition to
239 the playlist.
240
241 B<Default>: C<1 hour and 15 minutes>.
242
243 =back
244
245 =head2 [db]
246
247 =over
248
249 =item B<path> = I<DSN>
250
251 PostgresQL database name to use for local storage.
252
253 B<Default>: C<mpd-feeder>
254
255 =item B<user> = I<name>
256
257 PostgreSQL user name to connect as.
258
259 B<Default>: none.
260
261 =item B<password> = I<secret>
262
263 Password to use when connecting to PostgreSQL.
264
265 B<Default>: none.
266
267 =back
268
269 See F<init.sql> file in the distribution for commands to initializa the
270 database.
271
272 =head1 COPYRIGHT & LICENSE
273
274 Copyright © 2021 Damyan Ivanov L<dam+mpdfeeder@ktnx.net>
275
276 This program is free software: you can redistribute it and/or modify it under
277 the terms of the GNU General Public License version 3 as published by the Free
278 Software Foundation.
279
280 This program is distributed in the hope that it will be useful, but WITHOUT ANY
281 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
282 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
283
284 You should have received a copy of the GNU General Public License along with
285 this program.  If not, see <http://www.gnu.org/licenses/>.