Re: [Rhythmbox-devel] retreive rythmbox status via shell script.....



On Tue, Apr 26, 2005 at 04:07:33PM -0400, mat nicholson wrote:
> so, this is where i stand now. i have breifly broswed things such as the 
> rhythmbox-gaim plugin etc to see how they get their data from rthymbox, 
> however i would liek to avoid writting a program/plugin, and keep this 
> script based. is tehre a way for me to contact rhythmbox from a diffrent 
> term/from cron? is there a way to trigger something (a command) when 
> rhythmbox changes songs?

A couple of ideas:

You could try DISPLAY=:0 rhythmbox --print-playing .. bit of a hack
though.

$ ls -al /proc/`pidof rhythmbox`/fd | egrep '\.(mp3|ogg)$' \
	| cut -d' ' -f11-

.. even more of a hack, won't work for songs played off network shares,
and will probably screw up if you're importing songs when it runs.  But
it looks clever.

It's actually pretty easy to write a bonobo client in python:

#!/usr/bin/env python

import CORBA
import bonobo.activation
import string
import bonobo
import bonobo.ui
import gobject

_ACTIVATION_FLAG_EXISTING_ONLY = 1<<2;

def _song_cb(listener, event, ev):
	global rhythmbox
	properties = rhythmbox.getPlayerProperties()
	info = properties.getValue("song").value()
	properties.unref()
	if info is not None:
		print "now playing " + info.path

rhythmbox = bonobo.activation.activate(
	"repo_ids.has('IDL:GNOME/Rhythmbox:1.0')",
	[], _ACTIVATION_FLAG_EXISTING_ONLY)
if rhythmbox is not None:
	properties = rhythmbox.getPlayerProperties()
	bonobo.event_source_client_add_listener(properties, _song_cb,
		"Bonobo/Property:change:song")
	properties.unref()
	_song_cb(None, None, None)
	bonobo.ui.main()
else:
	print "Rhythmbox isn't running"

and you can make it do basically anything in the _song_cb function.
It fails pretty badly if you restart rhythmbox, though..

-jonathan.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]