X-Git-Url: https://git.draconx.ca/gitweb/mpdhacks.git/blobdiff_plain/d9b445c9f21cba5539cdc2f1103ca686a71e8a29..11b0f1bb5bdfc26be4cfb98201e18219eff5614c:/mpdmenu.pl diff --git a/mpdmenu.pl b/mpdmenu.pl index 2b593b0..d4120f6 100755 --- a/mpdmenu.pl +++ b/mpdmenu.pl @@ -3,7 +3,7 @@ use strict; use Getopt::Long; -use IO::Socket; +use IO::Socket::INET6; use constant { MPD_MJR_MIN => 0, @@ -46,7 +46,7 @@ $artist = decode_utf8($artist) if defined($artist); $title = decode_utf8($title) if defined($title);; # Connect to MPD. -my $sock = new IO::Socket::INET( +my $sock = new IO::Socket::INET6( PeerAddr => $host, PeerPort => $port, Proto => 'tcp' @@ -138,11 +138,11 @@ if (defined $album) { my $key = $_; my $a_album = sanitise($key); - open THUMB, "-|", "$FVWM/scripts/thumbnail.sh", + open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh", "--small", "--music", $albums{$key}; my $thumb = ; close THUMB; - die("Incompetent use of thumbnail.sh") if ($?); + die("Incompetent use of thumbnail.zsh") if ($?); $thumb =~ s/\n//sg; $thumb = "%$thumb%" if (-f $thumb); @@ -154,7 +154,7 @@ if (defined $album) { cmd("DestroyFunc MakeMenuMPDArt_$i"); cmd("AddToFunc MakeMenuMPDArt_$i + I DestroyMenu MenuMPDArt_$i - + I -PipeRead \"exec $FVWM/mpdmenu.pl " + + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl " ."--menu MenuMPDArt_$i " ."--album ".shellify($key, 1)." " ."--artist ".shellify($artist, 1)."\""); @@ -234,11 +234,11 @@ if (defined $album) { $t_artist = sanitise($t_artist); $t_title = sanitise($t_title); - open THUMB, "-|", "$FVWM/scripts/thumbnail.sh", + open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh", "--small", "--music", $t_file; my $thumb = ; close(THUMB); - die("Incompetent use of thumbnail.sh") if ($?); + die("Incompetent use of thumbnail.zsh") if ($?); $thumb =~ s/\n//sg; $thumb = "%$thumb%" if (-f $thumb); @@ -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 = ; - my $scan = ; - close(THUMB); - die("Incompetent use of thumbnail.sh") if ($?); + open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh", + "--image", "--music", $entry{file}; + my $thumb = ; + my $scan = ; + close(THUMB); + die("Incompetent use of thumbnail.zsh") 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 \"\""); + 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%\" " @@ -333,14 +339,14 @@ if (defined $album) { cmd("DestroyFunc MakeMenuMPDTitle"); cmd("AddToFunc MakeMenuMPDTitle + I DestroyMenu MenuMPDTitle - + I -PipeRead \"exec $FVWM/mpdmenu.pl " + + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl " ."--menu MenuMPDTitle " ."--title ".shellify($entry{Title}, 1)."\""); cmd("DestroyFunc MakeMenuMPDAlbum"); cmd("AddToFunc MakeMenuMPDAlbum + I DestroyMenu MenuMPDAlbum - + I -PipeRead \"exec $FVWM/mpdmenu.pl " + + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl " ."--menu MenuMPDAlbum " ."--album ".shellify($entry{Album}, 1)." " ."--artist ".shellify($entry{Artist}, 1)."\""); @@ -348,7 +354,7 @@ if (defined $album) { cmd("DestroyFunc MakeMenuMPDArtist"); cmd("AddToFunc MakeMenuMPDArtist + I DestroyMenu MenuMPDArtist - + I -PipeRead \"exec $FVWM/mpdmenu.pl " + + I -PipeRead \"exec $FVWM/scripts/mpdmenu.pl " ."--menu MenuMPDArtist " ."--artist ".shellify($entry{Artist}, 1)."\"");