title: How can I set the rating of a song playing in Rhythmbox 2.96?
body: <p>I am trying to create a Python plugin which will set the rating of the currently playing song in Rhythmbox 2.96.  It appears that Rhythmbox 2.96 doesn't let you use the API (Python modules) to set the rating of a song anymore; player related actions have been dropped in favor of MPRIS.</p>
  
  <p>I then tried looking at using dbus with MPRIS but MPRIS doesn't have a spec for setting the rating of a song either.  After a lot of digging, I found <a href="http://bazaar.launchpad.net/~jjardon/rhythmbox/trunk/view/head:/remote/dbus/rb-set-rating.py">this sample</a> in the Rhythmbox codebase and adapted it into a test script.  </p>
  
  <p>It works, but the SetEntryProperties method is causing Rhythmbox to freeze for about 30 seconds. Here is the Python script.  </p>
  
  <hr>
  
  <p>Instructions:</p>
  
  <ol>
  <li><p>Copy the code into a file called rate.py</p></li>
  <li><p>Start rhythmbox from a terminal using </p>
  
  <pre><code>rhythmbox -D rate
  </code></pre></li>
  <li><p>In Rhythmbox, enable the Python Console from the plugins</p></li>
  <li><p>Start the Python Console and run</p>
  
  <pre><code>   execfile('/path/to/rate.py')
  </code></pre></li>
  <li><p>You will see the print output in the terminal and Rhythmbox freezes for about 20-30 seconds.</p></li>
  </ol>
  
  <hr>
  
  <pre><code># rhythmbox -D rate
  # Rhythmbox: Edit &gt; Plugins &gt; Python Console enabled
  # Play a song
  # Open Rhythmbox Python Console
  # execfile('/path/to/rate.py')
  
  import sys
  import rb
  from gi.repository import Gtk, Gdk
  
  def rateThread(rating):
          try:
              currentSongURI = shell.props.shell_player.get_playing_entry().get_playback_uri()
              print "Setting rating for " + currentSongURI
  
              from gi.repository import GLib, Gio
              bus_type = Gio.BusType.SESSION
              flags = 0
              iface_info = None
  
              print "Get Proxy"
              proxy = Gio.DBusProxy.new_for_bus_sync(bus_type, flags, iface_info,
                                                     "org.gnome.Rhythmbox3",
                                                     "/org/gnome/Rhythmbox3/RhythmDB",
                                                     "org.gnome.Rhythmbox3.RhythmDB", None)
  
              print "Got proxy"
              rating = float(rating)
              vrating = GLib.Variant("d", rating)
              print "SetEntryProperties"
              proxy.SetEntryProperties("(sa{sv})", currentSongURI, {"rating": vrating})
              print "Done"
          except:
              print sys.exc_info()
  
          return False
  
  def rate():
          if shell.props.shell_player.get_playing_entry():
              Gdk.threads_add_idle(100, rateThread, 3)
  
  rate()
  </code></pre>
  
  <p>The exception that gets printed is:</p>
  
  <pre><code> Desktop/test2.py:41: (&lt;class 'gi._glib.GError'&gt;, GError('Timeout was
   reached',),  &lt;traceback object at 0x913e554&gt;)
  </code></pre>
  
  <p>My knowledge of Python/dbus is limited, so I don't understand why that error is occurring. I'd appreciate any help with it.</p>
  
  <p>Also, if you know of a better way of setting the rating of a song in Rhythmbox through code, it would be welcome too!</p>
  
  <p>I am using Ubuntu 12.04, if it makes a difference.</p>