views:

177

answers:

1

I would like the capability to get/set the rating associated with a specific track through a Python. How do I achieve this?

+2  A: 

You can use Rhythmbox' D-Bus interface. I have written a small script that can get/set the rating and displays a notification, all acting on the currently playing song.

The script is here: http://kaizer.se/wiki/code/rhrating.py

Addendum one: I promise I write more beautiful Python when it's not a throwaway script!
Addendum two: The missing Usage string is ./rhrating.py [NEWRATING 0..5]

Addendum three: If I filter the script and take out the parts that exactly set the rating of a song at filesystem location uri, it's this:

import dbus
bus = dbus.Bus()

service_name = "org.gnome.Rhythmbox"
sobj_name = "/org/gnome/Rhythmbox/Shell"
siface_name = "org.gnome.Rhythmbox.Shell"

def set_rating(uri, rating):
    searchobj = bus.get_object(service_name, sobj_name)
    shell = dbus.Interface(searchobj, siface_name)
    shell.setSongProperty(uri, "rating", float(rating))
kaizer.se