Sharing Clementine song status in Empathy

      Comments Off on Sharing Clementine song status in Empathy

Found this handy python script for sharing Clementine song status in Empathy….. regrettably it did not work on my Ubuntu 12.10 desktop installation….
Apparently you have to add a line (see the second line) about the character encoding nowadays….. so just to make it easier for other people… here’s the source…

# coding=utf8
import dbus
session_bus = dbus.SessionBus()
player = session_bus.get_object('org.mpris.clementine', '/Player')
iface = dbus.Interface(player, dbus_interface='org.freedesktop.MediaPlayer')
metadata = iface.GetMetadata()
status = "♫ ".decode('utf8')+" "+metadata["title"]+' - '+metadata["artist"]
#print status
from gi.repository import TelepathyGLib as Tp
from gi.repository import GObject
loop = GObject.MainLoop()
am = Tp.AccountManager.dup()
am.prepare_async(None, lambda *args: loop.quit(), None)
am.set_all_requested_presences(Tp.ConnectionPresenceType.AVAILABLE,'available', status)

original source (2nd line added, and a few cosmetic changes to the status line to my wishes): 

I named it and put a oneliner bash file called next to it which I call when I want that song status shared…. that just polls every 20 seconds…..
[bash]while true ; do ./ ; sleep 20 ; done[/bash]
I´d say there’s enough possibilities there. I’ve been thinking of creating a few bots/daemons to keep things in check, like my monitoring system. This little script is right up that alley…..

I do advise to lower the polling frequency if you don’t care about having it updated every 20 seconds, to spare resources. As soon as you get above a minute, I´d just make a cron script out of it…
Another thing I’ve been thinking is the offset between constantly updating the status vs checking it and only updating it on change. No idea what the difference in impact is on instant messengers nowadays. I imagine the later…. but this is food for thought on a later moment..

If I do a fun experiment with this later I’ll jot it down…. If *you* do, let us know 🙂

ps. like mentioned in the source, you might need to install lib telepathy for this, but as aptitude isnt installed anymore by default, just use apt-get
[bash]apt-get install libtelepathy-glib-dev[/bash]
Source: old site