From: Nick Bowler Date: Sun, 25 Jul 2021 17:04:02 +0000 (-0400) Subject: mpdexec: Add "verbose" option to print commands sent to MPD. X-Git-Url: https://git.draconx.ca/gitweb/mpdhacks.git/commitdiff_plain/5227a49aa2672e4fae2b118926fa84bb7af6fa24 mpdexec: Add "verbose" option to print commands sent to MPD. In order to add readpicture support to the thumbnailer in addition to albumart, we need a better way to distinguish which commands returned what results from the server. An easy way to do that is to just print the commands. --- diff --git a/mpdexec.pl b/mpdexec.pl index 72f81fe..e83146b 100755 --- a/mpdexec.pl +++ b/mpdexec.pl @@ -27,11 +27,11 @@ use FindBin; use lib "$FindBin::Bin"; use MPDHacks; -my ($quiet, $binary, $ignore_errors, $download); +my ($quiet, $verbose, $binary, $ignore_errors, $download); sub print_version { print < \$quiet, 'no-quiet' => sub { $quiet = 0; }, + 'verbose|v' => \$verbose, + 'no-verbose' => sub { $verbose = 0 }, 'binary|b:s' => \$binary, 'no-binary' => sub { $binary = undef; }, @@ -100,6 +104,7 @@ if ($binary) { } } $quiet = 1 if (defined($binary) && $binary eq ""); +$verbose = 0 if ($quiet); my $sock = MPD::connect(binmode => ":raw"); @@ -118,6 +123,12 @@ sub read_binary { 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; @@ -130,7 +141,7 @@ sub mpd_exec { $downloadseq = 2; } - print $sock encode('UTF-8', join(' ', @_), Encode::FB_QUIET), $/; + mpd_send(@_); while (<$sock>) { $_ = decode('UTF_8', $_, Encode::FB_QUIET); @@ -162,12 +173,13 @@ sub mpd_exec { } 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";