playerctl icon indicating copy to clipboard operation
playerctl copied to clipboard

Feature request: strict HH:MM:SS formatting of `{{ duration(position) }}`

Open Djhg2000 opened this issue 2 years ago • 0 comments

While developing a completely separate project with an 8 character array of 7-segment displays, I found it quite useful to have the time of the currently playing video printed out on the display.

Long story short, the truncated format for short videos (as in 1:23 instead of 00:01:23) made it a little more complicated to actually make it fit the entire display. The temporary solution I came up with to print this to the serial port was the following:

playerctl position -F -f "{{ duration(position) }}" | sed -e 's#\([0-9][0-9]*\):\([0-9][0-9]*\)#+\1 \2#g' -e 's#+\([0-9]\) #+0\1 #g' -e 's#+#+00 #g' -e 's#+00 \([0-9][0-9] [0-9][0-9]\):\([0-9][0-9]\)#+\1 \2#g' > /dev/ttyACM0

The amount of sed mangling in there is either awkward or hilarious. :sweat_smile:

One of those expressions is for prepending + (to reset the position of the display to the first character) and to replacing : with (an empty space), you probably shouldn't care about that one since that's a limitation of my display. But if I could have the timestamp padded with 0 into a strict HH:MM:SS format through some option then that would make the "1-liner" a lot cleaner (and hopefully easier to shoehorn into other projects).

I can of course share the source of the display hardware if you want, right now it's just a Raspberry Pi Pico and a dirt cheap shift register LED display.

Djhg2000 avatar Jul 26 '22 03:07 Djhg2000