【发布时间】:2012-05-21 01:37:43
【问题描述】:
我正在尝试创建一个 Python 插件,该插件将在 Rhythmbox 2.96 中设置当前播放歌曲的评分。 Rhythmbox 2.96 似乎不再允许您使用 API(Python 模块)来设置歌曲的评分;已放弃与播放器相关的操作,转而支持 MPRIS。
然后我尝试查看将 dbus 与 MPRIS 结合使用,但 MPRIS 也没有设置歌曲评级的规范。经过大量挖掘,我在 Rhythmbox 代码库中找到了this sample,并将其改编为测试脚本。
它有效,但 SetEntryProperties 方法导致 Rhythmbox 冻结大约 30 秒。这是 Python 脚本。
说明:
将代码复制到名为 rate.py 的文件中
-
使用
从终端启动节奏盒rhythmbox -D rate 在 Rhythmbox 中,通过插件启用 Python 控制台
-
启动 Python 控制台并运行
execfile('/path/to/rate.py') 您将在终端中看到打印输出,并且 Rhythmbox 会冻结大约 20-30 秒。
# rhythmbox -D rate
# Rhythmbox: Edit > Plugins > Python Console enabled
# Play a song
# Open Rhythmbox Python Console
# execfile('/path/to/rate.py')
import sys
import rb
from gi.repository import Gtk, Gdk
def rateThread(rating):
try:
currentSongURI = shell.props.shell_player.get_playing_entry().get_playback_uri()
print "Setting rating for " + currentSongURI
from gi.repository import GLib, Gio
bus_type = Gio.BusType.SESSION
flags = 0
iface_info = None
print "Get Proxy"
proxy = Gio.DBusProxy.new_for_bus_sync(bus_type, flags, iface_info,
"org.gnome.Rhythmbox3",
"/org/gnome/Rhythmbox3/RhythmDB",
"org.gnome.Rhythmbox3.RhythmDB", None)
print "Got proxy"
rating = float(rating)
vrating = GLib.Variant("d", rating)
print "SetEntryProperties"
proxy.SetEntryProperties("(sa{sv})", currentSongURI, {"rating": vrating})
print "Done"
except:
print sys.exc_info()
return False
def rate():
if shell.props.shell_player.get_playing_entry():
Gdk.threads_add_idle(100, rateThread, 3)
rate()
打印出来的异常是:
Desktop/test2.py:41: (<class 'gi._glib.GError'>, GError('Timeout was
reached',), <traceback object at 0x913e554>)
我对 Python/dbus 的了解有限,所以我不明白为什么会发生该错误。如有任何帮助,我将不胜感激。
另外,如果您知道通过代码在 Rhythmbox 中设置歌曲评分的更好方法,也欢迎!
我使用的是 Ubuntu 12.04,如果它有所作为的话。
【问题讨论】:
-
刚刚看到你在我的问题上留下的评论。我对此感兴趣...如果您今晚还没有发现,我保证会搜索它(当然是出于我自己的自私原因:))。如果您已经知道,请回答您自己的问题,以便其他人可以看到解决方案。 :D
-
@Mamsaac - 谢谢你提醒我,我已经更新了答案,虽然不完美。
标签: python ubuntu gio rhythmbox