在lua脚本中从DBus中读取艺术家元数据 - 输出奇怪

我正在尝试在 Lua 脚本中从 nuvolaplayer 中读取 DBus metadata。 (track) 标题和专辑字段显示正常,但艺术家数据出现异常:

lgi.rec 0x7f9ee8005c90:GLib.Variant Underwater Dub  Dictionary

这里期望的是 "Sly&Robbie",而不是 "lgi.rec 0x7f9ee8005c90:GLib.Variant"

当我使用 d-feet 查看该值时,可以看到 xesam:artist 字段与其他字段不同,因为它被 [] 包围。

这是我使用的代码:

local lgi = require 'lgi'
local Gio = lgi.require 'Gio'
local core = require 'lgi.core'
local GLib = lgi.require 'GLib'
local type,unpack = type,unpack
local bus = Gio.bus_get_sync(Gio.BusType.SESSION)

local ret,err = bus:call(
    "org.mpris.MediaPlayer2.nuvolaplayer",
    --"org.gnome.Rhythmbox3",
    "/org/mpris/MediaPlayer2",
    "org.freedesktop.DBus.Properties",
    "GetAll",
    GLib.Variant.new_tuple(
    {
        GLib.Variant("s","org.mpris.MediaPlayer2.Player")
    }, 1),
    nil,
    Gio.DBusConnectionFlags.NONE,
    -1, -- Timeout
    nil, -- Cancellable
    function(conn, res)
        local ret, err = bus:call_finish(res)
        print("here",err)

        local returnValue1, returnValue2 = unpack(ret.value)
        if not err then
            print("META", returnValue1.Metadata["xesam:artist"],
                returnValue1.Metadata["xesam:album"],
                returnValue1.Metadata["xesam:title"])
        end
    end
)

local main_loop = GLib.MainLoop()
main_loop:run()
点赞
用户991303
用户991303

领域xesam:artist是字符串(艺术家)的一个列表/数组。可能Lua需要专门处理该类型以进行打印,例如迭代数组并从中提取纯字符串。

2014-10-23 17:51:20