You are not logged in.

#1 2018-02-01 19:18:36

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Media Player Info Script

It returns the currently playing title for mpd,audacious,mocp (and more can be added by writing a simple plugin).
It is geared towards tint2's Executor plugin: icon & tooltip support, dynamically adapting player controls.
It can output the title on one or several lines, and ellipsize it when it gets too long.

I already wrote about it some time ago, but this is a major overhaul and frankly deserves its own thread.

excerpt from the README:

Called without arguments, it returns the title (filled as intelligently as
possible, whether it's a network stream or a file without metadata) of the
currently playing song to stdout, clipped and ellipsized to a width of 60
chars, and a more verbose tooltip to stderr. Multiple players are considered
and the first fit chosen in this order: "mpd audacious mocp".
If you don't use this script with tint2, you might want to discard the tooltip:
mpi-panel 2>/dev/null

Features

Query a list of audio players for currently playing song info.
This list defaults to builtin capabilities + all plugin files found inside the
plugin directory. Identically named plugins override builtins.
If this query gets multiple results, make one choice based on certain rules
(see -p, -P and -S) and format the output to stdout.

The output format is fairly limited; if you need more finegrained control you
should write your own plugin (one example is provided) or use the media 
player's own functionality. Instead, the idea is to

 - make best use of the (limited) horizontal space on your panel
 - not be limited to 1 media player (incl. playback control)

mpi-panel is made with tint2's executor plugin in mind (but in no way limited
to it) and caters to most of its unique features:

 - show an icon in addition to the text (optional)
 - continuous operation (optional)
 - tooltip is sent to stderr
 - custom actions for clicking in the executor (left/right/middle/wheel)

Formatting options

 a) shortening to a max. length (default: 60) and ellipsizing (see -w and -e)
 b) folding output into more than 1 line, respecting word boundaries (see -l)

- which happens in exactly that order. The idea is to use the output in a
horizontal panel, where the number of lines is fixed, and horizontal space is
limited but not fixed. A third formatting option is to

 c) prepend a line with the path to an icon representing current player state
    (play/pause/stop). This has tint2's executor plugin in mind. See -i and -s.

Full information (still formatted but not ellipsized, one line for each player
on the list & running) is output to stderr (e.g. as tooltip for tint2's
executor plugin).

Supported players
    mpd audacious mocp (see -p for full description)

Last edited by ohnonot (2021-06-15 06:12:50)

Offline

#2 2018-02-02 09:50:06

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Media Player Info Script

^ i had considered that, and maybe i will again later, since i have a clearer picture of what this script is supposed to do now.
unfortunately mocp does not support this.
i also suspect that mpris cannot replace all functionality of this script.

bugfixes

soon after pushing this last night i realised that i missed a rather large brainfart:
the title needs to be formatted depending on whether it's a network stream or not.
network streams tend to have the song title hardcoded to "Artist - Title", and the actual artist field can be filled with a too-lengthy description of the radio station...
i have now opted to use the title field for network streams, and "Artist - Title" for properly tagged local files.

mocp does this by default, but none of the others!
nevertheless the script uses its own mechanism even for mocp.

please update your local copy.

The multiplayer functionality was an interesting and not too difficult logical problem to implement, but it can be pretty confusing, esp. since the player controls change and it can become impossible to change back to one's favorite player.
i'm working on an option that will mitigate that.

Last edited by ohnonot (2018-02-02 09:54:59)

Offline

#3 2018-02-08 18:47:28

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Media Player Info Script

1 or 2 more commits since last message.
i have a few ideas for additions already, and will definitely implement something, but it is stable now (famous last words).
i think the plugin thing is pretty neat, you can not only add other media players but hack existing functionality in a relatively simple way (plugin overrides builtin).

I've been using this script for over 2 years - ever since this.
i think it could be useful for others, too.

i'd like to ask your opinions (and do some testing):

is it pointless? because?

does it have too many features? or too little?

does it have something unique for you, that you cannot reproduce with your media player's own features?

what should i develop further, what features should i add?

Last edited by ohnonot (2018-02-08 18:47:54)

Offline

#4 2018-02-10 21:12:54

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Media Player Info Script

added notifications on song change and albumart.

Offline

#5 2018-02-17 20:20:25

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Media Player Info Script

the script can now also extract album art from local files.
i also fixed a glitch where enabling the -I option actually disabled the display of normal play/pause/stop icons, and improved mpd title recognition for e.g. soundcloud playlists.

somebody asked about openBSD support; it seems the BSDs don't ship with some fairly standard linux utilities. the missing pidof completely breaks the script.
anybody have an idea how i can reproduce this command:
pidof mediaplayer >/dev/null 2>&1
with another utility, that is available on both linux & bsd? without using pipes or too much additional logic?
the script just needs to know whether the media player is running.

i have updated the list of dependencies and will see what i can do about it.

Last edited by ohnonot (2018-02-18 07:21:32)

Offline

#6 2018-02-17 22:40:30

obscurant
Member
Registered: 2017-08-06
Posts: 150

Re: Media Player Info Script

This is great! Thanks so much.

Last edited by obscurant (2018-02-17 23:18:22)

Offline

#7 2018-02-18 04:05:14

Döbbie03
Resident Metalhead
From: New Zealand
Registered: 2015-09-29
Posts: 3,871

Re: Media Player Info Script

Very cool, personally in Tint2 I use this command in an executor

{ echo "$(playerctl metadata title | awk -v len=40 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }' | tr -d '&' | awk '{print "♫ " $0 ""}')"; echo - "$(playerctl metadata artist)" - "$(playerctl metadata album)"; } | tr "\n" " "

"All we are is dust in the wind, dude"
                                       - Theodore "Ted" Logan
"Led Zeppelin didn't write tunes that everybody liked, they left that to the Bee Gees."
                                       - Wayne Campbell

Offline

#8 2018-02-18 07:19:40

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Media Player Info Script

^^ thanks.

^ nice. however, the text UI players supported by my script don't use mpris.
also i always maintain that a well-written bash script that relies on builtins as much as possible is lighter on resources than a one liner with many pipes.
of course my script has many more features and does not really compare to that.

Offline

#9 2018-02-18 08:09:21

Döbbie03
Resident Metalhead
From: New Zealand
Registered: 2015-09-29
Posts: 3,871

Re: Media Player Info Script

ohnonot wrote:

the text UI players supported by my script don't use mpris.

Yeah that's where that one liner falls short.

Very cool script by the way.


"All we are is dust in the wind, dude"
                                       - Theodore "Ted" Logan
"Led Zeppelin didn't write tunes that everybody liked, they left that to the Bee Gees."
                                       - Wayne Campbell

Offline

#10 2018-02-19 12:50:01

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Media Player Info Script

some more bugfixing.
i'm also going through the script with shellcheck now, that should add a few more fixes & commits.

@dobbie03: thanks for making me aware of playerctl.
might come in handy at some point.

btw, i think it should be possible to write an mpris plugin for this script.

Offline

Board footer

Powered by FluxBB