bin/disorder-notify: Maybe report currently playing track on state change.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 21 Jul 2018 14:18:07 +0000 (15:18 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 21 Jul 2018 14:57:58 +0000 (15:57 +0100)
This involves fiddling with the `now_playing' function so that it can
find out the current track for itself if necessary.

(Initially I did this on `enable_random' and `enable_play', but that
leads to duplicate now-playing reports because a `playing' notification
will follow unless we never actually stopped playing anything anwyay.
So now we only report on resume.)

bin/disorder-notify

index 757e12f..780aadc 100755 (executable)
@@ -27,8 +27,13 @@ sub cmd (@) {
   else { return "??? multiple lines"; }
 }
 
-sub now_playing ($) {
+sub now_playing (;$) {
   my ($track) = @_;
+  if (!defined $track) {
+    my @r = cmd "playing";
+    if ($r[0] =~ /^track\s+(.*)$/) { $track = $1; }
+    else { return; }
+  }
   my %p;
   for my $p ("artist", "album", "title")
     { $p{$p} = cmd "part", $track, "display", $p; }
@@ -74,14 +79,16 @@ for (;;) {
     if ($what eq "state") {
       my $st = $f[2];
       my $msg;
+      my $np = 0;
       if ($st eq "disable_random") { $msg = "random play disabled"; }
       elsif ($st eq "enable_random") { $msg = "random play enabled"; }
       elsif ($st eq "disable_play") { $msg = "playing disabled"; }
       elsif ($st eq "enable_play") { $msg = "playing enabled"; }
       elsif ($st eq "pause") { $msg = "paused"; }
-      elsif ($st eq "resume") { $msg = "playing"; }
+      elsif ($st eq "resume") { $msg = "playing"; $np = 1; }
       else { next LINE; }
       notify "DisOrder state", ucfirst $msg;
+      now_playing if $np;
       }
     } elsif ($what eq "playing") {
       now_playing $f[2];