From 16e1b76de8c54ee642443d119fb3f7ed7e2c5716 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 2 Jun 2020 17:13:00 +0100 Subject: [PATCH] bin/disorder-notify: Print the current play position in `now-playing' output. --- bin/disorder-notify | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/disorder-notify b/bin/disorder-notify index d26a565..b2967e2 100755 --- a/bin/disorder-notify +++ b/bin/disorder-notify @@ -142,11 +142,19 @@ sub decode_track_name ($\%) { } } +sub fmt_duration ($) { + my ($n) = @_; + return sprintf "%d:%02d", int $n/60, $n%60; +} + sub format_now_playing (\%) { my ($info) = @_; exists $info->{track} or return "Nothing."; my $r = "$info->{artist}: ‘$info->{title}’"; $r .= ", from ‘$info->{album}’" if $info->{album}; + exists $info->{sofar} && exists $info->{length} and + $r .= sprintf " (%s/%s)", + fmt_duration $info->{sofar}, fmt_duration $info->{length}; $r .= "\n(chosen by $info->{submitter})" if exists $info->{submitter}; return $r; } @@ -157,6 +165,8 @@ sub get_now_playing ($) { defined $r or return {}; my %info = split_fields $r; decode_track_name $sk, %info; + exists $info{sofar} and + $info{length} = send_command $sk, "length", $info{track}; return \%info; } -- 2.11.0