]> git.draconx.ca Git - fvwmconf.git/blobdiff - scripts/mpdmenu.pl
mpdmenu: Use geeqie instead of gqview.
[fvwmconf.git] / scripts / mpdmenu.pl
index 4639211c0a62f00b946c4e254dddf2dc60e90a29..4ef7ecefafb61b13c0c13707d4ea09febfbb3ae1 100755 (executable)
@@ -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'
@@ -100,8 +100,8 @@ if (defined $album) {
 
                next if (defined $artist && !$accept{albumdir($t_file)});
 
-               $t_artist = sanitise($t_artist);
-               $t_title  = sanitise($t_title);
+               $t_artist = sanitise($t_artist, 0);
+               $t_title  = sanitise($t_title, 0);
 
                my $cmd = sprintf "AddToMenu $menu \"%d\t%s - %s\""
                                  ." Exec mpc playid %d",
@@ -136,13 +136,13 @@ if (defined $album) {
        use locale;
        foreach (sort keys(%albums)) {
                my $key      = $_;
-               my $a_album  = sanitise($key);
+               my $a_album  = sanitise($key, 1);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
+               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
                                         "--small", "--music", $albums{$key};
                my $thumb = <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);
@@ -173,7 +173,7 @@ if (defined $album) {
        $menu = "MenuMPDTitle" unless defined $menu;
 
        # Open and close brackets.
-       my ($ob, $cb) = ("[\[~〜<(ー−-]", "[\]~〜>)ー−-]");
+       my ($ob, $cb) = ("[\[~〜<〈(ー−-]", "[\]~〜>〉)ー−-]");
 
        $_ = $title;
 
@@ -186,17 +186,18 @@ if (defined $album) {
        s/ -Practice Track-//;                        # Fair Heaven
        s/〜世界で一番アナタが好き〜//;               # Pure Heart
        s/〜彼方への哀歌//;                           # 十二幻夢
+       s/ sora no uta ver.//;                       # 美しい星
 
        s/\s*-remix-$//; # Otherwise "D-THREAD -remix-" doesn't work right.
 
        # Deal with titles like "blah (ABC version)".
-       s/\s*$ob.*(style|mix|edit|edition|ver\.?|version|カラオケ)$cb?$//i;
+       s/\s*$ob.*(style|mix|edit|edition|ver\.?|version|melody|カラオケ)$cb?$//i;
 
        # Deal with titles like "blah (without XYZ)".
-       s/\s*$ob((e\.)?piano|english|japanese|inst|tv|without|w\/o|off|back|short|karaoke|game).*//i;
+       s/\s*$ob\s*((e\.)?piano|english|japanese|inst|tv|without|w\/o|off|back|short|karaoke|game).*//i;
 
        # Deal with titles like "blah instrumental".
-       s/\s+(instrumental|off vocal|short)(\s+(size|version|s))?$//i;
+       s/\s+(instrumental|off vocal|short|tv)([\s-]+(mix|size|version))?$//i;
        s/\s+without\s+\w+$//i;
 
        my $basetitle  = $_;
@@ -230,15 +231,16 @@ if (defined $album) {
                );
 
                # MPD searches are case-insensitive.
-               next if (!($t_title =~ m/(\P{Latin}|^)\Q$basetitle\E(\P{Latin}|$)/));
-               $t_artist = sanitise($t_artist);
-               $t_title  = sanitise($t_title);
+               next if (!($t_title =~ m/(\P{Latin}|^)\Q$basetitle\E(\P{Latin}|$)/ || $t_title =~ m/\Q$basetitle\E/i));
+
+               $t_artist = sanitise($t_artist, 1);
+               $t_title  = sanitise($t_title, 1);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
+               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
                                         "--small", "--music", $t_file;
                my $thumb = <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);
@@ -281,7 +283,7 @@ if (defined $album) {
                }
                die("Failed data query\n") unless (keys(%entry) > 0);
 
-               open THUMB, "-|", "$FVWM/scripts/thumbnail.sh",
+               open THUMB, "-|", "$FVWM/scripts/thumbnail.zsh",
                                         "--image", "--music",  $entry{file};
                my $thumb = <THUMB>;
                my $scan  = <THUMB>;
@@ -293,14 +295,14 @@ 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})."\" "
-                       ."Popup MenuMPDTitle");
-               cmd("AddToMenu $menu \"Artist:  ".sanitise($entry{Artist})."\" "
-                       ."Popup MenuMPDArtist");
-               cmd("AddToMenu $menu \"Album:   ".sanitise($entry{Album})."\" "
-                       ."Popup MenuMPDAlbum");
+               cmd("AddToMenu $menu \"Title:   ".sanitise($entry{Title}, 0)
+                       ."\" Popup MenuMPDTitle");
+               cmd("AddToMenu $menu \"Artist:  ".sanitise($entry{Artist}, 0)
+                       ."\" Popup MenuMPDArtist");
+               cmd("AddToMenu $menu \"Album:   ".sanitise($entry{Album}, 0)
+                       ."\" Popup MenuMPDAlbum");
                cmd("AddToMenu $menu \"\" Nop");
        } else {
                cmd("AddToMenu $menu \"<Song info unavailable>\"");
@@ -368,7 +370,8 @@ print $sock "close\n";
 sub sanitise
 {
        $_ = $_[0];
-       s/([\$&@%^*])/\1\1/g;
+       s/&/&&/g if ($_[1]);
+       s/([\$@%^*])/\1\1/g;
        s/"/\\"/g;
        return $_;
 }