X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/534a10c119de31237acbb8fd75a7a55e3cf2d922..382e25f7d8c569293f3182f10c3b15ffb93b5e90:/awesome/widgets/mpc.lua?ds=inline diff --git a/awesome/widgets/mpc.lua b/awesome/widgets/mpc.lua index d870f2f..a3c5b87 100644 --- a/awesome/widgets/mpc.lua +++ b/awesome/widgets/mpc.lua @@ -95,7 +95,6 @@ function mpc:_connect() self._output, self._input = nil, nil self:_error(err) else - do_read() line = tostring(line) if line == "OK" or line:match("^ACK ") then local success = line == "OK" @@ -112,9 +111,22 @@ function mpc:_connect() else local _, _, key, value = string.find(line, "([^:]+):%s(.+)") if key then - self._pending_reply[string.lower(key)] = value + if key == "binary" then + value = tonumber(value) + local data = {} + while value > 0 do + local b = assert(obj:read_bytes(value)) + table.insert(data, b.data) + value = value - #b + end + local w = obj:read_bytes(1) -- read newline at end of binary + self._pending_reply[string.lower(key)] = table.concat(data) + else + self._pending_reply[string.lower(key)] = value + end end end + do_read() end end) end @@ -223,6 +235,30 @@ function mpc:currentsong() return currentsong end +local function escape(str) + return "\"" .. str .. "\"" +end + +function mpc:albumart(uri, handler) + local image_table = {} + local get_art_at + get_art_at = function(off) + self:send("albumart " .. escape(uri) .. " " .. tostring(off), function(success, data) + if not success then + handler(success, data) + end + table.insert(image_table, data.binary) + if data.binary and #data.binary > 0 then + get_art_at(off + #data.binary) + else + data.binary = table.concat(image_table) + handler(success, data) + end + end) + end + get_art_at(0) +end + --[[ -- Example on how to use this (standalone)