I am trying to create a Python plugin that will set the rating of the current song in Rhythmbox 2.96. It seems that Rhythmbox 2.96 does not allow you to use APIs (Python modules) to set the song rating more; player-related actions were dropped in favor of MPRIS.
Then I tried to use dbus with MPRIS, but MPRIS has no specification for setting the song rating. After a lot of digging, I found this sample in the Rhythmbox database and adapted it into a test script.
This works, but the SetEntryProperties method causes the Rhythmbox to freeze for about 30 seconds. Here is a Python script.
Instruction:
Copy the code into a file called rate.py
Start the rhythm box from the terminal using
rhythmbox -D rate
In Rhythmbox enable Python Console from plugins
Launch the Python console and run
execfile('/path/to/rate.py')
You will see the printout in the terminal, and the Rhythmbox freezes for about 20-30 seconds.
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()
The exception that is printed is:
Desktop/test2.py:41: (<class 'gi._glib.GError'>, GError('Timeout was
reached',), <traceback object at 0x913e554>)
My knowledge of Python / dbus is limited, so I don't understand why this error occurs. I would appreciate any help with this.
Also, if you know the best way to rate a song in Rhythmbox via code, that would be a plus too!
I use Ubuntu 12.04 if that matters.