]> git.draconx.ca Git - fvwmconf.git/blobdiff - scripts/mpdmenu.pl
MPD script updates.
[fvwmconf.git] / scripts / mpdmenu.pl
index 25a56b30eaa15725d5a1f4952fdd9c0d67856751..c36fad7ab64e7fa051a1104e4cc2183ede6058ae 100755 (executable)
@@ -1,4 +1,13 @@
 #!/usr/bin/perl
+#
+# Copyright © 2018,2010,2012,2019 Nick Bowler
+#
+# Silly little script to generate an FVWM menu with various bits of MPD
+# status information and controls.
+#
+# 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;
 
@@ -12,7 +21,8 @@ use constant {
 };
 
 use utf8;
-use encoding 'utf8';
+use open qw(:std :utf8);
+binmode(STDOUT, ":utf8");
 use Encode;
 
 sub cmd
@@ -49,7 +59,8 @@ $title  = decode_utf8($title)  if defined($title);;
 my $sock = new IO::Socket::INET6(
        PeerAddr => $host,
        PeerPort => $port,
-       Proto => 'tcp'
+       Proto => 'tcp',
+       Timeout => 2
 ) or die("could not open socket: $!.\n");
 binmode($sock, ":utf8");
 
@@ -104,7 +115,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);
@@ -200,6 +212,9 @@ if (defined $album) {
        s/\s+(instrumental|off vocal|short|tv)([\s-]+(mix|size|version))?$//i;
        s/\s+without\s+\w+$//i;
 
+       # Deal with separate movements in classical pieces.
+       s/: [IVX]+\..*//;
+
        my $basetitle  = $_;
        my $_basetitle = $basetitle;
 
@@ -245,7 +260,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 {
@@ -295,7 +312,7 @@ if (defined $album) {
 
                if (-f $thumb) {
                        cmd("AddToMenu $menu \"*$thumb*\" "
-                               ."Exec exec gqview ".shellify($scan, 0));
+                               ."Exec exec geeqie ".shellify($scan, 0));
                }
                cmd("AddToMenu $menu \"Title:   ".sanitise($entry{Title}, 0)
                        ."\" Popup MenuMPDTitle");
@@ -311,25 +328,25 @@ if (defined $album) {
 
        if ($state eq "play" || $state eq "pause") {
                cmd("AddToMenu $menu \"\t\tNext%$icons/next.svg:16x16%\" "
-                       ."Exec exec mpc next");
+                       ."Exec exec $FVWM/scripts/mpdexec.pl next");
                cmd("AddToMenu $menu \"\t\tPause%$icons/pause.svg:16x16%\" "
-                       ."Exec exec mpc pause") if ($state eq "play");
+                       ."Exec exec $FVWM/scripts/mpdexec.pl pause");
                cmd("AddToMenu $menu \"\t\tPlay%$icons/play.svg:16x16%\" "
-                       ."Exec exec mpc play") if ($state eq "pause");
+                       ."Exec exec $FVWM/scripts/mpdexec.pl play");
                cmd("AddToMenu $menu \"\t\tStop%$icons/stop.svg:16x16%\" "
-                       ."Exec exec mpc stop");
+                       ."Exec exec $FVWM/scripts/mpdexec.pl stop");
                cmd("AddToMenu $menu \"\t\tPrev%$icons/prev.svg:16x16%\" "
-                       ."Exec exec mpc prev");
+                       ."Exec exec $FVWM/scripts/mpdexec.pl previous");
        } elsif ($state eq "stop") {
                cmd("AddToMenu $menu \"\t\tPlay%$icons/play.svg:16x16%\" "
-                       ."Exec exec mpc play");
+                       ."Exec exec $FVWM/scripts/mpdexec.pl play");
        } else {
                die("Unknown MPD state!\n");
        }
 
        cmd("AddToMenu $menu \"\" Nop");
        cmd("AddToMenu $menu \"\t\tShuffle%$icons/shuffle.svg:16x16%\" "
-               ."Exec exec mpc shuffle");
+               ."Exec exec $FVWM/scripts/mpdexec.pl shuffle");
 
        cmd("DestroyMenu MenuMPDTitle");
        cmd("AddToMenu   MenuMPDTitle  DynamicPopUpAction MakeMenuMPDTitle");