From: Mark Wooding Date: Sat, 21 Jul 2018 14:18:07 +0000 (+0100) Subject: bin/disorder-notify: Maybe report currently playing track on state change. X-Git-Url: https://git.distorted.org.uk/~mdw/profile/commitdiff_plain/a367c2fe3a46d3e07313d756b7ef5e0bec84fcf3?hp=30068e6d43270e37b0f5c3620cb1ec43d54d1d61 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.) --- 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];