我使用python-dbus的小脚本和来自org.kde.amarok / Player的事件:
org.freedesktop.MediaPlayer.TrackChange
以下是代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import dbus
import sys
import time
import gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus_loop = DBusGMainLoop(set_as_default=True)
dbus_session = dbus.SessionBus(mainloop=dbus_loop)
dbus_amarok = None
dbus_psi = None
try:
dbus_amarok = dbus_session.get_object('org.kde.amarok', '/Player')
dbus_psi = dbus_session.get_object('org.psi-im.Psi', '/Main')
except dbus.exceptions.DBusException:
sys.stderr.write('Psi or Amarok not launched/reachable.\n')
sys.stderr.flush()
sys.exit(1)
def hdl_amarok_sig(sender=None):
try:
title = sender.get('title').encode('utf-8')
album = sender.get('album').encode('utf-8')
artist = sender.get('artist').encode('utf-8')
play_msg = '♪ {} ({}) by {} ♪'.format(title, album, artist)
print(play_msg)
dbus_psi.setStatus('online', play_msg)
except AttributeError:
pass
dbus_amarok.connect_to_signal('TrackChange', hdl_amarok_sig)
loop = gobject.MainLoop()
loop.run()
然后例如:
♪ Með suð í eyrum (Með suð í eyrum við spilum endalaust) by Sigur Rós ♪
♪ Með suð í eyrum (Með suð í eyrum við spilum endalaust) by Sigur Rós ♪
这就是打印的内容以及psi当然收到的内容。并且在网上找不到任何关于我的信息,我在FreeBSD,Debian unstable和Fedora 18(KDE4)上进行了测试。
答案 0 :(得分:0)
好吧,这是Amarok的一个错误。使用克莱门汀玩家不要发送两次事件。 Bug报道。