I have finally managed to display properly the title of the song played in Clementine on the toolbar. So, if anyone is interested, here is the way I managed to do it. Note that there are probably better ways to do it.
First, I have simplified the "mediaplayer.py script to get rid of the Conky part and made a few modifications.
Code: Select all
#!/usr/bin/env python3
#
# mediaplayer.py
#
# Print the metadata of a mediaplayer on conky and control it
# This can also be used as a stand-alone command line application
#
# Author : Amish Naidu
# I release this in the public domain, do with it what you want.
import dbus, argparse, subprocess
#Return a string containing time in HH:MM:SS format from microseconds
def fmt_time(microseconds):
seconds = microseconds/1000000
return '{:02}:{:02}:{:02}'.format(int(seconds//360), int((seconds%360)//60), int(seconds%60))
if __name__ == '__main__':
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description='''\
Connect to a media player through dbus to get the metadata or control it.
This can be used to output the current track playing (and it's attributes) on *conky*
%(prog)s can print the metadata of the track currently playing and
make the player perform an action
If the bus was not found, 'Not found' will be printed.
If any property is not found, 'Unknown' will be used/printed.
The 'player' must support MPRIS 2.0''',
epilog='''\
Examples of usage:
To display the Artist, Title and Album with Clementine
$ python3 %(prog)s clementine -atm
To display the Artist, Title, Album and Genre but this time with ${alignr} between the field and it's value
$ python3 %(prog)s vlc -atmg -r
Using the long form arguments with Audacious
$ python3 %(prog)s audacious --album --artist --length
To switch track
$ python3 %(prog)s amarok --action=next
$ python3 %(prog)s clementine --action=play
Author: Amish Naidu (amhndu --at-- gmail)
Please report any bugs.
''')
parser.add_argument('-i', '--running', action='store_true', help="print 'yes' if the 'player' is running, 'no' otherwise")
parser.add_argument('player', action='store',
help="name of the player e.g. 'clementine', or 'vlc' or 'audacious' or 'xmms2'")
parser.add_argument('-r', '--conkyalignr', action='store_true', help='Add ${alignr} before values')
parser.add_argument('-w', '--width', type=int,
help="Truncate lines upto 'width' characters. No limit if less than zero (default)", default=-1)
parser.add_argument('-t', '--title', action='store_true', help='title of the track')
parser.add_argument('-a', '--artist', action='store_true', help='artist name')
parser.add_argument('-m', '--album', action='store_true', help='album name')
parser.add_argument('-g', '--genre', action='store_true', help='genre of the current track')
parser.add_argument('-y', '--year', action='store_true', help='year of the track')
parser.add_argument('-l', '--length', action='store_true', help='lenght of the track')
parser.add_argument('-e', '--elapsed', action='store_true', help='elapsed time for the track')
parser.add_argument('-p', '--progress', action='store_true',
help='progress of the track as a percent (not formatted)')
parser.add_argument('-n', '--track', action='store_true', help='track number')
parser.add_argument('-c', '--cover', help='Make a (soft) symlink at the specified location to the album art')
parser.add_argument('--cover_default', help='If the the album art could not be found from the player, make a link to this')
parser.add_argument('--action', action='store', help='make the player perform an action : next, prev, play, pause, volume up/down by 0.1',
choices=['next', 'prev', 'pause', 'play', 'playpause', 'volup', 'voldown'])
args = parser.parse_args()
try:
#MPRIS 2.0 Spec http://specifications.freedesktop.org/mpris-spec/latest/index.html
player = dbus.SessionBus().get_object('org.mpris.MediaPlayer2.' + args.player, '/org/mpris/MediaPlayer2')
metadata = player.Get('org.mpris.MediaPlayer2.Player', 'Metadata',
dbus_interface='org.freedesktop.DBus.Properties')
running = True
except dbus.exceptions.DBusException:
running = False
if args.running:
print("yes" if running else "no")
if not running:
print("")
else:
if args.artist:
print(metadata['xesam:artist'][0] if 'xesam:artist' in metadata else 'Unknown Artist', end="")
if args.title:
print(" -", metadata['xesam:title'] if 'xesam:title' in metadata else 'Unknown Title')
if args.album:
print("(", metadata['xesam:album'] if 'xesam:album' in metadata else 'Unknown Album',")")
if args.genre:
print(metadata['xesam:genre'][0] if 'xesam:genre' in metadata else 'Unknown Genre')
if args.year:
print(metadata['xesam:contentCreated'][:4] if 'xesam:contentCreated' in metadata else 'Unknown')
if args.track:
print(metadata['xesam:trackNumber'] if 'xesam:trackNumber' in metadata else 'Unknown')
Code: Select all
Plugin {
type = genmon
config {
# Command = python3 mediaplayer.py audacious -at
Command = ~/.config/fbpanel/fbp_scripts/mediaplayer_short.py clementine -at
CharLength = 100
PollingTime = 5
TextSize = medium
TextColor = #e6e6e6
}
}
Code: Select all
~/path/to/mediaplayer_short.py clementine -at
Here is the final result, between the desktop indicator and the systray on the right of the panel on fluxbox and xfce.

