-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpimpd2
executable file
·577 lines (388 loc) · 14.2 KB
/
pimpd2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
#!/usr/bin/perl
# vim:ft=perl:et:sw=2:
use lib 'lib';
use strict;
no warnings 'experimental::smartmatch';
use vars qw($VERSION);
my $APP;
sub usage {
pod2usage(
msg => "$APP v$VERSION\n",
verbose => 1,
exitval => 0,
);
}
BEGIN {
$APP = 'pimpd2';
$VERSION = '0.348';
use Pod::Usage;
if( (!@ARGV) or ($ARGV[0] =~ m/--?h(?:elp)?\z/) ) {
usage();
exit;
}
}
use App::Pimpd;
use App::Pimpd::Player;
use App::Pimpd::Info;
use App::Pimpd::Shell;
use App::Pimpd::Commands;
use App::Pimpd::Transfer;
use App::Pimpd::Validate;
use App::Pimpd::Collection::Search;
use App::Pimpd::Collection::Album;
use App::Pimpd::Playlist;
use App::Pimpd::Playlist::Search;
use App::Pimpd::Playlist::Favorite;
use App::Pimpd::Playlist::Randomize;
use Term::ExtendedColor qw(fg);
use File::LsColor qw(ls_color);
use Getopt::Long;
GetOptions(
'np|now-playing' => sub { print current(), "\n"; },
'i|info' => \&info,
'lsa|songs' => sub { _lsa(@ARGV); },
'l|laa|albums' => sub {
print "$_\n" for albums_by_artist(join(' ',@ARGV));
},
'randomize' => sub { print "$_\n" for randomize(@ARGV); },
'ra|random-album' => sub { print "$_\n" for randomize_albums(@ARGV); },
'rt|random-track' => sub { _rt(); },
'af|add' => sub { _add_files(@ARGV); },
'a|apl|add-playlist' => sub { add_playlist(@ARGV); },
'lsplaylists' => sub { print "$_\n" for list_all_playlists(); },
'pls|playlist' => sub { show_playlist(); },
'da|delete-album' => sub { delete_album(); },
'p|play' => sub { play(@ARGV); },
's|stop' => sub { stop(); },
'k|kill' => sub { player_destruct(); },
'sh|shell' => sub { \&spawn_shell(@ARGV); },
'rma|rmalbum' => sub { remove_album_from_playlist(@ARGV); },
'cp|copy' => sub { cp(@ARGV ? @ARGV : $config{target_directory}) },
'cpa|copy-album' => sub {
cp_album(@ARGV ? @ARGV : $config{target_directory})
},
'fav|favorite|love' => sub { add_to_favlist(@ARGV); }, # FIXME
'loved' => sub {
if(already_loved($mpd->current->file)) {
printf("%s, %s by %s is loved.\n",
fg('bold', 'Yes'),
fg($c[10], $mpd->current->title),
fg($c[2], fg('bold', $mpd->current->artist)),
);
}
else {
printf("%s, %s by %s is not loved yet.\n",
fg('bold', 'No'),
fg($c[10], $mpd->current->title),
fg($c[2], fg('bold', $mpd->current->artist)),
);
}
},
'unlove' => sub { remove_favorite(@ARGV); },
'aa|add-album' => sub {
add_to_playlist( map{ $_->file } get_album_songs(@ARGV) );
},
'slove' => sub {
my @files = search_favlist(@ARGV);
print "$_\n" for @files;
},
'spl|search-playlist|splaylist' => sub { _search_playlist(@ARGV); },
# XXX this is basicly the same as --slove
# we maybe want to have functionality for searching playlists that's not made
# by pimpd2.
'sap|search-all-pls' => sub { print "$_\n" for search_all_playlists(@ARGV); },
'sdb|search-db' => sub { print "$_\n" for search_db_quick(@ARGV); },
'sar|search-artist' => sub { print "$_\n" for search_db_artist(@ARGV); },
'sal|search-album' => sub { print "$_\n" for search_db_album(@ARGV); },
'set|search-title' => sub { print "$_\n" for search_db_title(@ARGV); },
'next' => sub { next_track(); },
'prev' => sub { previous_track(); },
'clear' => sub { clear_playlist(); },
'crop' => sub { crop(@ARGV); },
'crossfade|xfade' => sub { crossfade(@ARGV); },
'pause' => sub { toggle_pause; },
'repeat' => sub { toggle_repeat; },
'random' => sub { toggle_random; },
'status' => sub { print status(), "\n"; },
'stats' => sub { stats(); },
'host' => sub {
# FIXME one way, or another...
my($host, $port, $password, $stream) = @ARGV;
App::Pimpd::mpd_init($host, $port, $password);
},
'debug' => sub { _debug(); },
'h|help' => \&usage,
'version' => sub { print "$APP v$VERSION\n" and exit 0; },
'man' => sub { pod2usage( verbose => 3 ); },
);
sub _rt {
play_pos_from_playlist(random_track_in_playlist());
print current(), "\n";
return;
}
# Wrapper for songs_on_album()
sub _lsa {
my($album, $artist) = @_;
$album or $album = $mpd->current->album;
# no colors if not connected to a terminal
if(!-t STDOUT) {
print $_->file, "\n" for songs_on_album($album, $artist);
}
else {
printf "%s\n", ls_color($_->file) for songs_on_album($album, $artist);
}
return;
}
sub _search_playlist {
my $result = search_playlist(@_); # hashref
if( keys(%{$result}) < 2 ) {
play_pos_from_playlist( keys(%{$result}) );
}
queue(keys(%{$result})); #FIXME queue should take arrayref
return;
}
sub _add_files {
my @files = @_;
if(!-t STDIN) {
while(<STDIN>) {
push(@files, $_);
}
}
add_to_playlist(@files);
return;
}
sub _debug {
my $i = 0;
for(@c) {
print fg($_, "\$c[$i]"), "\n";
$i++;
}
return;
}
=pod
=head1 NAME
pimpd2 - Perl Interface for the Music Player Daemon 2
=head1 DESCRIPTION
pimpd2 is a command-line based MPD client that implements all the features
the author was missing from the other awesome client, mpc.
=head1 FEATURES
=head2 -np, --now-playing
Show basic song information on a single line.
=head2 -i, --info
Show all available song information and MPD server status.
=head2 -cp, --copy
Copy the currently playing song to destination.
If destination is omitted, uses the C<target_directory> variable from the
configuration file.
=head2 -cpa, --copy-album
Copy the currently playing album to destination.
If destination is omitted, uses the C<target_directory> variable from the
configuration file.
=head2 -sh, --shell
Spawn the interactive pimpd2 shell.
All the regular features can be used. Commands that return data that can be
added to the current playlist will do so automagically for convenience, since
we can not read from standard input while being interactive.
=head2 -q, --queue
Queue tracks. Arguments must be valid playlist position IDs as shown in the
C<--playlist> output.
You can also use the C<--search-playlist> command if the tracks to be queued
follows a pattern.
=head1 PLAYLIST INTERACTION
=head2 -pls, --playlist
Show the current playlist.
=head2 --playlists
List all playlists known by MPD.
=head2 -af, --add-files
Add files to the current playlist.
Can read from standard input:
pimpd2 --randomize 42 Nirvana | pimpd2 -af
Accepts file arguments:
pimpd2 -af ~/music/Nirvana/Bleach/*.flac
=head2 -a, --add-playlist
Add playlist to the current playlist.
If not given a full name, and the name partially matches existing playlists,
prompts for input:
pimpd2 -a 2010
0 2010-12-indie
1 2010-12-other
2 2010-12-pop
3 2010-12-punk_rock
4 2010-12-rock
5 2010-12-undef
choice:
If choice equals 'all', all matching playlists are added.
=head2 -r, --randomize
Return B<n> random songs from the collection.
The first argument is the number of songs, the second argument is an optional
artist name. If an artist name is specified, will only return random songs from
that particular artist.
If no arguments are specified, returns 100 random songs.
If you want to add the results to the current playlist, pipe it to C<--add-files>:
pimpd2 -r 12 | pimpd2 -af
Or use the interactive shell ( C<-sh> ) which does this for you automatically.
=head2 -ra, --random-album
Return B<n> random full albums.
A pipe to C<--add-files> will add the results to the current playlist.
=head2 -rt, --random-track
Start playback of a random song in the current playlist.
=head2 -rma, --rmalbum
Given a string, searches the current playlist for matching albums, and remove
them from the playlist. The string can be a regular expression.
=head2 -da, --delete-album
Delete the current album from disk.
=head2 -f, --love
Favorize, or love, the current song.
If called with zero arguments, the song will be saved to a playlist following
this naming scheme:
%year-%month-%genre.m3u
Else, the argument is used for the playlist name, thus:
pimpd2 --love lovesongs
adds the song to lovesongs.m3u
=head2 --loved
Check if the currently playing song is already loved or not.
=head2 --unlove
Unlove songs matching given PATTERN.
=head2 --lsplaylists
Lists available playlists.
=head2 --slove
Search the database with loved songs for PATTERN.
If PATTERN is omitted, returns all loved songs.
=head2 -spl, --search-playlist
Search the current playlist for string, possibly a regular expression.
If more then one song is found, queues up the results. See C<--queue>.
=head1 COLLECTION INTERACTION
=head2 -lsa, --songs
List all songs on album.
If no argument is specified, use the album tag from the currently playing song.
A pipe to C<--add-files> will add the results to the current playlist:
pimpd2 -lsa Stripped | pimpd2 -af
=head2 -l, --albums
List all albums where artist is featured.
If no argument is specified, use the artist tag from the currently playing song.
=head2 -sdb, --search-db
Search the database for string, possibly a regular expression.
A pipe to C<--add-files> will add the results to the current playlist:
=head2 -sar, --search-artist
Search the database for artist.
A pipe to C<--add-files> will add the results to the current playlist:
=head2 -sal, --search-album
Search the database for album.
A pipe to C<--add-files> will add the results to the current playlist:
=head2 -set, --search-title
Search the database for title.
A pipe to C<--add-files> will add the results to the current playlist:
=head2 --stats
Display statistics about MPD
=head2 --status
Display MPD status
=head1 CONTROLS
=head2 -n, --next
Play the next track in the playlist.
=head2 -p, --previous
Play the previous track in the playlist.
=head2 -cl, --clear
Clear the current playlist.
=head2 -cr, --crop
Remove all songs but the current one from the playlist.
=head2 -x, --xfade
Set crossfade.
=head2 --pause
Toggle playback status.
=head2 --repeat
Toggle repeat on/off
=head2 --random
Toggle random on/off
=head2 --play
Start playback.
If a remote stream URL and an external player is specified in the
configuration file, starts playback on the local machine as well as on the
MPD server.
=head2 --stop
Stop playback, locally and remote.
=head2 --kill
Stop local playback.
=head1 OPTIONS
-np, --now-playing basic song info on a single line
-i, --info full song info
-cp, --copy copy the current track
optional argument: destination
-cpa, --copy-album copy the current album
optional argument: destination
-sh, --shell spawn the interactive shell
-q, --queue queue tracks
=head2 Playlist
-pls, --playlist show the current playlist
--playlists list all known playlists
-af, --add-files add files to playlist
-a, --add-playlist add playlist
--randomize randomize a new playlist with n tracks
optional arguments: quantity, artist
-ra, --random-album add n random full albums
optional arguments: quantity, artist
-rt, --random-track play a random song in the current playlist
-rma, --rmalbum remove album matching pattern from playlist
-da, --delete-album delete the current album from disk
-f, --love love song
--loved check if the current song is loved
-u, --unlove unlove songs matching pattern
-spl, --search-playlist search the current playlist for str
=head2 Collection
-lsa, --songs list songs on album
-l, --albums list albums by artist
optional argument: artist
-sdb, --search-db search database for pattern
-sar, --search-artist search database for artist
-sal, --search-album search database for album
-set, --search-title search database for title
--slove search the database with loved songs for pattern
--stats display statistics about MPD
--status display MPD status
=head2 Controls
-n, --next next track in playlist
-p, --previous previous track in playlist
-cl, --clear clear the playlist
-cr, --crop remove all songs but the current one from playlist
-x, --xfade set crossfade
--pause toggle playback status
--repeat toggle repeat mode
--random toggle random mode
-p, --play start playback (locally and remote)
-s, --stop stop playback (locally and remote)
-k, --kill stop playback (locally)
-h, --help show the help and exit
-m, --man show the manual and exit
-v, --version show version info and exit
=head1 ENVIRONMENT
pimpd2 will look for a configuration file in the following locations, in this
order:
$XDG_CONFIG_HOME/pimpd2/pimpd2.conf
~/.config/pimpd2/pimpd.conf
~/.pimpd2.conf
./pimpd2.conf
/etc/pimpd2.conf
=head1 AUTHOR
Magnus Woldrich
CPAN ID: WOLDRICH
http://japh.se
=head1 CONTRIBUTORS
None required yet.
=head1 REPORTING BUGS
Report bugs and/or feature requests to <[email protected]>, on L<rt.cpan.org>
or L<http://github.com/trapd00r/pimpd2/issues>.
=head1 COPYRIGHT
Copyright 2009, 2010, 2011, 2019- the B<pimpd2> L</AUTHOR> and
L</CONTRIBUTORS> as listed above.
=head1 LICENSE
This application is free software; you may redistribute it and/or modify it
under the same terms as Perl itself.
=head1 SEE ALSO
L<mpd(1)>
L<App::Pimpd::Collection::Album>, L<App::Pimpd::Collection::Search>,
L<App::Pimpd::Commands>, L<App::Pimpd::Doc>, L<App::Pimpd::Info>,
L<App::Pimpd::Player>, L<App::Pimpd::Playlist>,
L<App::Pimpd::Playlist::Favorite>, L<App::Pimpd::Playlist::Randomize>,
L<App::Pimpd::Playlist::Search>, L<App::Pimpd::Shell>, L<App::Pimpd::Transfer>,
L<App::Pimpd::Validate>
=cut