How do I get the currently playing song in Rhythmbox using Python

谁说胖子不能爱 提交于 2019-12-09 18:40:40

问题


Im using Ubuntu 12.04. I want to access Rhythymbox using Python .

This is how I've proceeded so far:

Ive gone through this site https://live.gnome.org/RhythmboxPlugins/WritingGuide , but it gives details on how to write plugins , which Im not interested in right now. Ive gone through a few tutorials which tells me to do this.

import dbus
session_bus = dbus.SessionBus()

proxy_obj = session_bus.get_object(
'org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player') 

But I am getting the following error

DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Rhythmbox was not provided by any .service files.

Could someone please point me in the right direction of what I would like to achieve?


回答1:


A workaround, used by lyricsdownloader.py, is:

import subprocess
import shlex

proc = subprocess.Popen(shlex.split('rhythmbox-client --no-start --print-playing-format %tt')))
title, err = proc.communicate()

Note: This does not work with Ubuntu 11.10, which shipped without rhythmbox-client.




回答2:


This might be useful. https://github.com/aliva/rhythmbox-microblogger

It is a twitter plugin for RhythmBox. So instead of twitter and Gtk, you can just take the current song.

from gi.repository import RB

RB.RhythmDBPropType.TITLE will give enum which you can use to get the title.




回答3:


I think that you've encountered a bug in Rhythmbox DBus interface described on Launchpad. Tracker says that fix is committed, but possibly your version doesn't have that fix.



来源:https://stackoverflow.com/questions/11939856/how-do-i-get-the-currently-playing-song-in-rhythmbox-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!