2012-08-13 106 views
4

使用Ubuntu 12.04的Im。我想用Python訪問Rhythymbox。如何使用Python獲取Rhythmbox中當前播放的歌曲

這是我到目前爲止已經着手:

伊夫通過這個網站 https://live.gnome.org/RhythmboxPlugins/WritingGuide走了,但它給出瞭如何編寫插件細節,即時消息在現在沒有興趣。我經歷了幾個教程,告訴我這樣做。

import dbus 
session_bus = dbus.SessionBus() 

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

但我收到以下錯誤

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

可能有人請指出我的,我想達到什麼樣的方向是正確的?

+0

你是指什麼訪問?你想要做什麼*具體*? – 2012-08-13 18:14:38

+0

我只想得到正在播放的歌曲的名稱。 – Manoj 2012-08-13 18:17:34

+0

也許你可以看一下'/ usr/lib/rhythmbox/plugins/im-status/im-status.py'中的im-status插件,它會把歌曲的名字放在pidgin/empathy中 – solarc 2012-08-13 18:23:12

回答

1

我認爲你遇到了Launchpad上描述的Rhythmbox DBus接口中的一個錯誤。 Tracker表示修復已經完成,但可能您的版本沒有修復。

+0

它還是發生在「修復發佈」之後很長時間 – NoBugs 2014-07-09 06:51:46

3

一種解決方法,通過使用lyricsdownloader.py是:

import subprocess 
import shlex 

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

注:這並不與Ubuntu 11.10,其出廠時沒有Rhythmbox的客戶端工作。

+0

如何捕獲標題作爲str?當我'打印標題'時,我得到'None'並且var測試爲NoneType ... – 2013-02-09 08:07:39

+0

這很好,但是請注意可以有一些同名的歌曲,但是在不同的文件夾中(例如,它們在不同的年份被唱過,但它們具有相同的名稱)。我嘗試刪除播放歌曲的方式,但問題是我無法弄清楚我應該刪除哪首歌。 (並祝好運我可以刪除另一首歌曲) – Tebe 2013-03-08 15:51:21

1

這可能會有用。 https://github.com/aliva/rhythmbox-microblogger

這是一個RhythmBox的twitter插件。所以,而不是嘰嘰喳喳和Gtk,你可以把目前的歌曲。

from gi.repository import RB 

RB.RhythmDBPropType.TITLE將給出你可以用來獲得標題的枚舉。

相關問題