我正在尝试创建一个Python插件,它将在Rhythmbox 2.96中设置当前正在播放的歌曲的等级。看来Rhythmbox 2.96不再允许你使用API(Python模块)来设置歌曲的分级;与播放器相关的操作已经被放弃,转而支持MPRIS。在
然后我尝试使用dbus和MPRIS,但MPRIS也没有设置歌曲评级的规范。经过大量的挖掘,我在Rhythmbox代码库中找到了this sample,并将其改编为一个测试脚本。在
它可以工作,但是SetEntryProperties方法导致Rhythbox冻结大约30秒。这是Python脚本。在
说明:
将代码复制到名为速率.py
使用从终端启动Rhythybox
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的了解有限,所以我不明白为什么会出现这种错误。如果有人帮我,我会很感激的。在
另外,如果你知道一个更好的方法,通过代码在Rhythbox中设置一首歌的评级,它也将是受欢迎的!在
我用的是Ubuntu12.04,如果有区别的话。在
在插件中设置等级
RhythyBox 2.9x确实提供了一个API来设置评级-除非您使用的是外部程序,如RhythyBox托盘图标,否则不需要通过dbus进行调用。在
评级在其内部数据库中作为双类型值保存。使用RhydredEntry,您可以使用
要设置分级,您需要使用RhythDB entry\u set函数:
^{pr2}$获取和设置评级的示例代码可以在CoverArt Browser插件(coverart)中找到_相册.py)在
github上的Rhythmbox Tray Icon plugin确实可以设置歌曲分级,但它是在Rhythmbox执行环境之外的中设置的。在
从here:
如果我试图直接在Rhythmbox插件中运行代码,它会再次冻结。然而,在Rhythmbox环境之外运行它非常好。我觉得这个很好,所以我把它作为答案。在
相关问题 更多 >
编程相关推荐