[Rhythmbox-devel] Scripts: delete currently playing file, skip etc



Hi,

recently hacked a few small scripts to remote-control rhythmbox via DBus,
especially to delete the currently running song from disk (needs
python-gnome installed, default on Ubuntu):

#!/usr/bin/python
import gnomevfs, dbus, os
try:
    bus = dbus.SessionBus()
    obj = bus.get_object('org.gnome.Rhythmbox','/org/gnome/Rhythmbox/Player')
    rbplayer = dbus.Interface(obj, 'org.gnome.Rhythmbox.Player')
    filename = rbplayer.getPlayingUri()
    nicename = gnomevfs.unescape_string_for_display(filename).replace("'","\'")
    if nicename.strip == '':
        nicename = filename
    os.environ['text']='<b>Delete this file?</b>\n%s' % nicename.replace('&', '&amp;')
    command = 'zenity --question --title "Delete this file?" --text "$text"'
    if os.system(command) == 0:
        rbplayer.next()
        gnomevfs.unlink(gnomevfs.URI(filename))
        #os.system("zenity --error --text ok")
except:
    os.system("zenity --error --text \"Delection failed!\"")


Another one for skipping:
#!/usr/bin/env python
import gnomevfs, os, dbus
try:
    bus = dbus.SessionBus()
    obj = bus.get_object('org.gnome.Rhythmbox','/org/gnome/Rhythmbox/Player')
    rbplayer = dbus.Interface(obj, 'org.gnome.Rhythmbox.Player')
    rbplayer.next()
except:
    pass

There are variations on this with rbplayer.previous(),
rbplayer.playPause(dbus.Boolean(1) and similar. There is a handy app
called dbus-viewer which helps to discover the interfaces of Rhythmbox and
any other registered applications.

Cheers
-- 
Gabriel Wicke




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