use lib "$FindBin::Bin";
use MPDHacks;
-my ($quiet, $binary, $ignore_errors, $download);
+my ($quiet, $verbose, $binary, $ignore_errors, $download);
sub print_version {
print <<EOF
-mpdexec.pl 0.8
+mpdexec.pl 0.9
Copyright © 2021 Nick Bowler
License GPLv3+: GNU General Public License version 3 or any later version.
This is free software: you are free to change and redistribute it.
-p, --port=PORT Connect to the MPD server on PORT, overriding defaults.
-q, --quiet Do not output any response messages. Only errors (on
standard error) or binary data (if enabled) are output.
+ -v, --verbose Print commands as they are submitted. If both --quiet
+ and --verbose are specified, --verbose has no effect.
-b, --binary[=FILE]
Output raw binary response data, which is normally not
written. If FILE is specified, the data is written there.
'quiet|q' => \$quiet,
'no-quiet' => sub { $quiet = 0; },
+ 'verbose|v' => \$verbose,
+ 'no-verbose' => sub { $verbose = 0 },
'binary|b:s' => \$binary,
'no-binary' => sub { $binary = undef; },
}
}
$quiet = 1 if (defined($binary) && $binary eq "");
+$verbose = 0 if ($quiet);
my $sock = MPD::connect(binmode => ":raw");
return $rc;
}
+sub mpd_send {
+ my $cmd = encode('UTF-8', join(' ', @_), Encode::FB_QUIET);
+ print "$cmd\n" if ($verbose);
+ print $sock $cmd, $/;
+}
+
my %downloadcmds = map { $_ => 1 } ( "albumart", "readpicture" );
sub mpd_exec {
my $downloadseq;
$downloadseq = 2;
}
- print $sock encode('UTF-8', join(' ', @_), Encode::FB_QUIET), $/;
+ mpd_send(@_);
while (<$sock>) {
$_ = decode('UTF_8', $_, Encode::FB_QUIET);
}
if (@ARGV) {
- mpd_exec(map { MPD::escape($_) } @ARGV)
+ mpd_exec(map { MPD::escape } @ARGV)
+} elsif ($ignore_errors) {
+ while (<>) { chomp; mpd_exec($_); }
} else {
- while (<>) {
- chomp;
- mpd_exec($_);
- }
+ mpd_send("command_list_begin");
+ while (<>) { chomp; mpd_send($_); }
+ mpd_exec("command_list_end");
}
print $sock "close\n";