How to use Rhythmbox python console

Solution 1:

The Rhythmbox Plugins Writing Guide has several examples of commands you can use in the Python console to control playback and modify Rhythmbox:

  • Play/Pause

    shell.props.shell_player.playpause()
    
  • Stop

    shell.props.shell_player.stop()
    
  • Next track

    shell.props.shell_player.do_next()
    
  • Add a song to the Play Queue

    shell.add_to_queue("file://awsome_song.ogg")
    
  • Display a visualization

    import gst
    goom = gst.element_factory_make ("goom")
    sink = gst.element_factory_make ("ximagesink")
    colour = gst.element_factory_make ("ffmpegcolorspace")
    b = gst.Bin()
    b.add (goom, colour, sink)
    b.add_pad(gst.GhostPad("sink", goom.get_pad("sink")))
    goom.link(colour)
    colour.link(sink)
    shell.get_player().props.player.add_tee(b)
    

Solution 2:

As with any Python object, you can find out a lot about it by using the dir() method on it. This will give you a good place to start.

You can access the main window through the 'shell' variable :
<rb.Shell object at 0x9e9675c (RBShell at 0x987b018)>
>>> dir(rb.Shell)
['__class__', '__cmp__', '__copy__', '__deepcopy__', '__delattr__', '__dict__',
'__doc__', '__format__', '__gdoc__', '__getattribute__', '__gobject_init__', 
'__grefcount__', '__gtype__', '__hash__', '__init__', '__module__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__',
'__subclasshook__', 'add_to_queue', 'add_uri', 'add_widget', 'append_source',
'chain', 'connect', 'connect_after', 'connect_object', 'connect_object_after',
'disconnect', 'disconnect_by_func', 'do_notify', 'emit', 'emit_stop_by_name',
'freeze_notify', 'get_data', 'get_party_mode', 'get_player',
'get_playlist_manager', 'get_properties', 'get_property',
'get_source_by_entry_type', 'get_ui_manager', 'guess_source_for_uri', 
'handler_block', 'handler_block_by_func', 'handler_disconnect',
'handler_is_connected','handler_unblock', 'handler_unblock_by_func', 'load_uri',
'notebook_set_page', 'notify', 'notify_custom', 'present', 'props',
'register_entry_type_for_source', 'remove_from_queue', 'remove_widget',
'set_data', 'set_properties', 'set_property', 'stop_emission', 'thaw_notify',
'toggle_visibility', 'weak_ref']

You can then dir() any of the interesting-looking properties, like 'get_player', perhaps.

Another good place to look is if you see a __doc__ attribute on the object.

>>> print rb.Shell.__doc__
Object RBShell

Signals from RBShell:
  visibility-changed (gboolean)
  visibility-changing (gboolean, gboolean) -> gboolean
  create-song-info (RBSongInfo, gboolean)
  removable-media-scan-finished ()
  notify-playing-entry (gboolean)
  notify-custom (guint, gchararray, gchararray, GdkPixbuf, gboolean)

Properties from RBShell:
  no-registration -> gboolean: no-registration
    Whether or not to register
  no-update -> gboolean: no-update
    Whether or not to update the library
  dry-run -> gboolean: dry-run
    Whether or not this is a dry run
  rhythmdb-file -> gchararray: rhythmdb-file
    The RhythmDB file to use
  playlists-file -> gchararray: playlists-file
    The playlists file to use
  selected-source -> RBSource: selected-source
    Source which is currently selected
  db -> RhythmDB: RhythmDB
    RhythmDB object
  ui-manager -> GtkUIManager: GtkUIManager
    GtkUIManager object
  clipboard -> RBShellClipboard: RBShellClipboard
    RBShellClipboard object
  playlist-manager -> RBPlaylistManager: RBPlaylistManager
    RBPlaylistManager object
  removable-media-manager -> RBRemovableMediaManager: RBRemovableMediaManager
    RBRemovableMediaManager object
  shell-player -> RBShellPlayer: RBShellPlayer
    RBShellPlayer object
  window -> GtkWindow: GtkWindow
    GtkWindow object
  prefs -> RBShellPreferences: RBShellPreferences
    RBShellPreferences object
  queue-source -> RBPlayQueueSource: queue-source
    Queue source
  library-source -> RBLibrarySource: library-source
    Library source
  sourcelist-model -> RBSourceListModel: sourcelist-model
    RBSourcelistModel
  sourcelist -> RBSourceList: sourcelist
    RBSourcelist
  source-header -> RBSourceHeader: source header widget
    RBSourceHeader
  visibility -> gboolean: visibility
    Current window visibility

Signals from GObject:
  notify (GParam)