]> git.draconx.ca Git - fvwmconf.git/commitdiff
mpdmenu: don't bail out when MPD doesn't give us a songid.
authorNick Bowler <draconx@gmail.com>
Sun, 1 Jun 2008 22:43:09 +0000 (18:43 -0400)
committerNick Bowler <draconx@gmail.com>
Sun, 1 Jun 2008 22:43:09 +0000 (18:43 -0400)
This occurs when MPD is running, but hasn't played a song yet.  Make the
menu usable to start the player in this case.

scripts/mpdmenu.pl

index 23569d5e17e29a35ea8c6571d8b6589c0f7ba90e..9b60cdfc70de55d32e4d1ee73573a4e4be9c92e2 100755 (executable)
@@ -263,43 +263,49 @@ if (defined $album) {
                        $songid = $2 if ($1 eq "songid");
                }
        }
-       die("Failed status query\n") unless (defined $state && defined $songid);
+       die("Failed status query\n") unless (defined $state);
 
-       print $sock "playlistid $songid\n";
-       while (<$sock>) {
-               last if (/^OK/);
-               die($_) if (/^ACK/);
+       cmd("AddToMenu $menu Playing Title") if ($state eq "play");
+       cmd("AddToMenu $menu Paused Title")  if ($state eq "pause");
+       cmd("AddToMenu $menu Stopped Title") if ($state eq "stop");
 
-               if (/^(\w+): (.*)$/) {
-                       $entry{$1} = $2;
+       if (defined $songid) {
+               print $sock "playlistid $songid\n";
+               while (<$sock>) {
+                       last if (/^OK/);
+                       die($_) if (/^ACK/);
+
+                       if (/^(\w+): (.*)$/) {
+                               $entry{$1} = $2;
+                       }
                }
-       }
-       die("Failed data query\n") unless (keys(%entry) > 0);
+               die("Failed data query\n") unless (keys(%entry) > 0);
 
-       open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
-                                "--image", "--music",  $entry{file};
-       my $thumb = <THUMB>;
-       my $scan  = <THUMB>;
-       close(THUMB);
-       die("Incompetent use of thumbnail.sh") if ($?);
+               open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
+                                        "--image", "--music",  $entry{file};
+               my $thumb = <THUMB>;
+               my $scan  = <THUMB>;
+               close(THUMB);
+               die("Incompetent use of thumbnail.sh") if ($?);
 
-       $thumb =~ s/\n//sg;
-       $scan  =~ s/\n//sg;
+               $thumb =~ s/\n//sg;
+               $scan  =~ s/\n//sg;
 
-       cmd("AddToMenu $menu Playing Title") if ($state eq "play");
-       cmd("AddToMenu $menu Paused Title")  if ($state eq "pause");
-       cmd("AddToMenu $menu Stopped Title") if ($state eq "stop");
-       if (-f $thumb) {
-               cmd("AddToMenu $menu \"*$thumb*\" "
-                       ."Exec exec gqview ".shellify($scan, 0));
+               if (-f $thumb) {
+                       cmd("AddToMenu $menu \"*$thumb*\" "
+                               ."Exec exec gqview ".shellify($scan, 0));
+               }
+               cmd("AddToMenu $menu \"Title:   ".sanitise($entry{Title})."\" "
+                       ."Popup MenuMPDTitle");
+               cmd("AddToMenu $menu \"Artist:  ".sanitise($entry{Artist})."\" "
+                       ."Popup MenuMPDArtist");
+               cmd("AddToMenu $menu \"Album:   ".sanitise($entry{Album})."\" "
+                       ."Popup MenuMPDAlbum");
+               cmd("AddToMenu $menu \"\" Nop");
+       } else {
+               cmd("AddToMenu $menu \"<Song info unavailable>\"");
+               cmd("AddToMenu $menu \"\" Nop");
        }
-       cmd("AddToMenu $menu \"Title:   ".sanitise($entry{Title})."\" "
-               ."Popup MenuMPDTitle");
-       cmd("AddToMenu $menu \"Artist:  ".sanitise($entry{Artist})."\" "
-               ."Popup MenuMPDArtist");
-       cmd("AddToMenu $menu \"Album:   ".sanitise($entry{Album})."\" "
-               ."Popup MenuMPDAlbum");
-       cmd("AddToMenu $menu \"\" Nop");
 
        if ($state eq "play" || $state eq "pause") {
                cmd("AddToMenu $menu \"\t\tNext%$icons/next.svg:16x16%\" "