]> git.rmz.io Git - dotfiles.git/commitdiff
awesome/mpc: add albumart function
authorSamir Benmendil <me@rmz.io>
Mon, 10 Aug 2020 20:27:59 +0000 (21:27 +0100)
committerSamir Benmendil <me@rmz.io>
Mon, 10 Aug 2020 21:05:30 +0000 (22:05 +0100)
The function will send multiple 'albumart' requests and put together the
binary response, then call the handler.

awesome/widgets/mpc.lua

index 4da4a815e09a0b6b921c077e0e93623961aa57e2..a3c5b879cb967183977b607ab0eb2ca4d3e0a2f4 100644 (file)
@@ -235,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)