|
我正在尝试创建一个Python插件,它将设置Rhythmbox 2.96中当前正在播放的歌曲的评级.似乎Rhythmbox 2.96不允许您使用API(Python模块)来设置歌曲的评级;球员相关的行动已被取消,有利于MPRIS.
然后我尝试使用dbus与MPRIS,但MPRIS也没有设置歌曲评级的规范.经过大量挖掘后,我在Rhythmbox代码库中找到了this sample并将其改编成测试脚本.
它有效,但SetEntryProperties方法导致Rhythmbox冻结约30秒.这是Python脚本.
说明:
>将代码复制到名为rate.py的文件中 >使用终端从终端启动rhythmbox
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: (
我对Python / dbus的了解有限,所以我不明白为什么会出现这种错误.我很感激任何帮助.
另外,如果您知道通过代码在Rhythmbox中设置歌曲评级的更好方法,也会受到欢迎!
我正在使用Ubuntu 12.04,如果它有所作为.
最佳答案
在插件中设置评级
Rhythmbox 2.9x确实提供了一个API来设置评级 – 除非你使用外部程序,如Rhythmbox托盘图标,否则无需通过dbus调用.
评级在其内部数据库中保持为双重类型值.使用RhythmDBEntry,您可以获得评级
rating = entry.get_double(RB.RhythmDBPropType.RATING)
要设置评级,您需要RhythmDB entry_set函数:
db=self.shell.props.db
db.entry_set(entry,RB.RhythmDBPropType.RATING,rating)
获取和设置评级的示例代码可以在CoverArt Browser插件中找到(coverart_album.py) (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|