python– 如何设置在Rhythmbox 2.96中播放的歌曲的评级?

python– 如何设置在Rhythmbox 2.96中播放的歌曲的评级?,第1张

概述我正在尝试创建一个Python插件,它将设置Rhythmbox 2.96中当前正在播放歌曲评级.似乎Rhythmbox 2.96不允许您使用API​​(Python模块)来设置歌曲的评级;球员相关的行动已被取消,有利于MPRIS.然后我尝试使用dbus与MPRIS,但MPRIS也没有设置歌曲评级的规范.经过大量挖掘后,我在Rhythmbox代码库中找到了

我正在尝试创建一个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 sysimport rbfrom gi.repository import Gtk,Gdkdef 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 Falsedef 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.dbdb.entry_set(entry,RB.RhythmDBPropType.rating,rating)

获取和设置评级的示例代码可以在CoverArt Browser插件中找到(coverart_album.py) 总结

以上是内存溢出为你收集整理的python – 如何设置在Rhythmbox 2.96中播放的歌曲的评级?全部内容,希望文章能够帮你解决python – 如何设置在Rhythmbox 2.96中播放的歌曲的评级?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1205559.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)