From a367c2fe3a46d3e07313d756b7ef5e0bec84fcf3 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 21 Jul 2018 15:18:07 +0100 Subject: [PATCH 1/1] bin/disorder-notify: Maybe report currently playing track on state change. 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/disorder-notify b/bin/disorder-notify index 757e12f..780aadc 100755 --- a/bin/disorder-notify +++ b/bin/disorder-notify @@ -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]; -- 2.11.0