#!/usr/bin/python -tt # skvidal@fedoraproject.org # gpl v2 blah blah import dbus import sys import time bus = dbus.SessionBus() # Explicitly try to start Rhythmbox. (success, status) = bus.start_service_by_name('org.gnome.Rhythmbox') # the one we're actually gonna use # you must enable this the mpris dbus interface plugin in rhythmbox for this to work n = 0 player = None # give it 10s to load things up if it wasn't running while n < 10: try: player = bus.get_object('org.mpris.MediaPlayer2.rhythmbox','/org/mpris/MediaPlayer2') except dbus.exceptions.DBusException, e: n+=1 time.sleep(1) else: break if not player: print "Giving up: tried to start rhythmbox and failed" sys.exit(1) # setup our interface iface = dbus.Interface(player, dbus_interface='org.mpris.MediaPlayer2.Player') if sys.argv[1] == '--next': iface.Next() elif sys.argv[1] == '--previous': iface.Previous() elif sys.argv[1] == '--playpause': # needs to better things if it has just started - to force the play again iface.PlayPause() #would be nice to add a 'what's playing' and bind it to a key so it would send #libnotify-accessible notifcation about what is playing