X-Git-Url: https://git.draconx.ca/gitweb/mpdhacks.git/blobdiff_plain/adba02b582138375bfd3adc9f68c0cd398827e7a..e49c1f846176562de0978ba1cd445b50b1094a2d:/mpdexec.pl diff --git a/mpdexec.pl b/mpdexec.pl index 0d477da..8147f1d 100755 --- a/mpdexec.pl +++ b/mpdexec.pl @@ -1,6 +1,6 @@ #!/usr/bin/env perl # -# Copyright © 2012,2019 Nick Bowler +# Copyright © 2012,2019-2020 Nick Bowler # # Send commands to MPD. Each command-line argument is quoted as necessary # so it appears as a single argument at the protocol level. The result is @@ -24,6 +24,10 @@ use IO::Socket::INET6; use Getopt::Long qw(:config gnu_getopt); +use FindBin; +use lib "$FindBin::Bin"; +use MPDHacks; + my $host = $ENV{MPD_HOST} // "localhost"; my $port = $ENV{MPD_PORT} // 6600; my ($quiet, $binary, $ignore_errors, $download); @@ -112,21 +116,6 @@ if (!(<$sock> =~ /^OK MPD ([0-9]+)\.([0-9]+)\.([0-9]+)$/)) { die "MPD failed to announce version: $!"; } -sub mpd_escape { - ($_) = @_; - - # No way to encode literal newlines in the protocol, so we convert - # any newlines in the arguments into a space, which can help with - # shell quoting. - s/\n/ /g; - - if (/[ \t\\"]/) { - s/[\\"]/\\$&/g; - return "\"$_\""; - } - return $_; -} - sub read_binary { my ($count) = @_; my $buf; @@ -185,7 +174,7 @@ sub mpd_exec { } if (@ARGV) { - mpd_exec(map { mpd_escape($_) } @ARGV) + mpd_exec(map { MPD::escape($_) } @ARGV) } else { while (<>) { chomp;