?

Log in

No account? Create an account
Handy Rhythmbox music detection script - LogJam [entries|archive|friends|userinfo]
LogJam

[ website | LogJam ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Handy Rhythmbox music detection script [Dec. 6th, 2003|11:51 pm]
LogJam

logjam

[psr]
[Current Mood |accomplished]
[Current Music |Regurgitator - Corpse Xplosion]

Hi, I hope this might be of some use to someone.

I use Rhythmbox as my music player and I wanted to be able to have logjam detect the playing music, so I wrote this little script to get the relevant details. This is the first thing I've ever written in Python and the first time I've used Bonobo, so I'm sorry if it looks a bit sloppy. Eight lines and it took me all evening :-)

There is a slight bug in this, if Rhythmbox isn't running then the script will start it. Does anyone know how to stop this?

You probably need the Python-gnome module installed for this to work I think.

#!/usr/bin/env python
import pygtk; pygtk.require("2.0")
import bonobo
obj = bonobo.activation.activate_from_id("OAFIID:GNOME_Rhythmbox")
song = obj.getPlayerProperties().getValue("song")
artist = song.value().artist
title = song.value().title
print(artist + " - " + title)
LinkReply

Comments:
From: technoshaman
2003-12-06 05:40 pm (UTC)
You probably need to use bonobo to check if the Rhythmbox object actually exists... the activate_from_id is what will crank it up if it isn't there alreddie. Or use something that will error and return blanks if the object isn't there already..... either way, whichever is easier.

Case 1: (using pseudocode here)
if (bonobo.object_exists_by_id("OAFIID:GNOME_Rhythmbox")
  # do your thing
else
  print(" ")
endif

Case 2:
obj=bonobo.activation.activate_from_id("OAFIID:GNOME_Rhythmbox")
if obj=ERROR_CODE
  print (" ")
  exit
else
# .... 
(Reply) (Thread)
[User Picture]From: psr
2003-12-06 05:51 pm (UTC)
As far as I can tell from looking at the docs Bonobo doesn't provide functions to use either of those approaches. I'm sure there is a way, but it doesn't seem to be listed in the API.
(Reply) (Parent) (Thread)
From: evan
2003-12-08 11:55 am (UTC)
that's good! it would be nice to make a version in c (see xmms-client in the cvs for an example) that logjam could then optionally install when you have rhythmbox installed...
(Reply) (Thread)
From: h3llraz0r
2003-12-27 09:15 pm (UTC)

Thanks

I just wanted to say thanks for the script.
(Reply) (Thread)