Rhythmbox: comment puis-je accéder au champ « note » d'une piste par script Python?
Question
Je voudrais la capacité d'obtenir / définir la note associée à une piste spécifique par un Python. Comment puis-je obtenir cela?
La solution
Vous pouvez utiliser « Rhythmbox Interface D-Bus. Je l'ai écrit un petit script qui peut obtenir / définir la note et affiche une notification, tous agissant sur la chanson en cours de lecture.
Le script est ici: http://kaizer.se/wiki/code/rhrating. py
Addendum un: Je promets que j'écris plus beau Python quand il est pas un script jetable
!
Addendum deux: La chaîne manquante d'utilisation est ./rhrating.py [NEWRATING 0..5]
Addendum trois: Si je filtre le script et retirer les parties qui définissent exactement la cote d'une chanson à l'emplacement du système de fichiers uri
, il est ceci:
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))