2

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

jldupont
  • 93,734
  • 56
  • 203
  • 318
  • possible duplicate of [How can I set the rating of a song playing in Rhythmbox 2.96?](http://stackoverflow.com/questions/10568599/how-can-i-set-the-rating-of-a-song-playing-in-rhythmbox-2-96) – mgibsonbr Nov 22 '12 at 10:47

1 Answers1

3

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))
u0b34a0f6ae
  • 48,117
  • 14
  • 92
  • 101