]> git.draconx.ca Git - mpdhacks.git/commitdiff
mpdmenu: Use a specialized script to send playid commands to MPD.
authorNick Bowler <nbowler@draconx.ca>
Sun, 26 Feb 2012 19:35:54 +0000 (14:35 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 29 Jun 2019 16:05:59 +0000 (12:05 -0400)
This avoids the dependency on a patched mpc.

mpdexec.pl [new file with mode: 0755]
mpdmenu.pl

diff --git a/mpdexec.pl b/mpdexec.pl
new file mode 100755 (executable)
index 0000000..9c6e069
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/env perl
+#
+# Copyright © 2012 Nick Bowler
+#
+# Simple program to send a command to MPD.  The result is printed to standard
+# output.
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
+
+use strict;
+
+use utf8;
+use encoding 'utf8';
+use IO::Socket::INET6;
+
+my $host = $ENV{MPD_HOST} // "localhost";
+my $port = $ENV{MPD_PORT} // 6600;
+
+my $sock = new IO::Socket::INET6(
+       PeerAddr => $host,
+       PeerPort => $port,
+       Proto    => 'tcp',
+) or die "failed to connect to MPD: $!";
+binmode($sock, ":utf8");
+
+if (!(<$sock> =~ /^OK MPD ([0-9]+)\.([0-9]+)\.([0-9]+)$/)) {
+       die "MPD failed to announce version: $!";
+}
+
+print $sock join(' ', @ARGV), "\n";
+while (<$sock>) {
+       last if (/^OK/);
+       print;
+       exit 1 if (/^ACK/);
+}
+
+print $sock "close\n";
+close $sock;
index bebf73bf9b5e2e574b307e2a74aa13e3a3826955..77a293f744f0a8f386391f30bd917208c0e7ba5c 100755 (executable)
@@ -104,7 +104,8 @@ if (defined $album) {
                $t_title  = sanitise($t_title, 0);
 
                my $cmd = sprintf "AddToMenu $menu \"%d\t%s - %s\""
-                                 ." Exec mpc playid %d",
+                                 ." Exec exec $FVWM/scripts/mpdexec.pl"
+                                 ." playid %d",
                                  $t_trackno, $t_artist, $t_title, $t_id;
 
                cmd($cmd);
@@ -248,7 +249,9 @@ if (defined $album) {
                $thumb =~ s/\n//sg;
                $thumb = "%$thumb%" if (-f $thumb);
 
-               cmd("AddToMenu $menu \"$thumb$t_artist - $t_title\" Exec mpc playid $t_id");
+               cmd("AddToMenu $menu \"$thumb$t_artist - $t_title\""
+                   ." Exec exec $FVWM/scripts/mpdexec.pl"
+                   ." playid $t_id");
        }
 } # end use locale workaround
 } else {