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

我正在尝试创建一个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)

相关文章

我最近重新拾起了计算机视觉,借助Python的opencv还有face_r...
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Poolin...
记得大一学Python的时候,有一个题目是判断一个数是否是复数...
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic ...
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic v...
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic ...