]> git.rmz.io Git - dotfiles.git/commitdiff
awesome/mpd_widget: request albumart when getting info
authorSamir Benmendil <me@rmz.io>
Mon, 10 Aug 2020 20:30:14 +0000 (21:30 +0100)
committerSamir Benmendil <me@rmz.io>
Mon, 10 Aug 2020 21:05:30 +0000 (22:05 +0100)
awesome/widgets/mpd_widget.lua

index b6cfec8686d57ee94a47fbefbe4de727866e76d7..2c6ab78ec3ce8888db1fbe4393a54de3a588958e 100644 (file)
@@ -48,21 +48,29 @@ function widget:get_info(callback)
     self._connection:send("status", function(_, s) status = s end)
 
     local song = nil
-    self._connection:send("currentsong", function(_, s) song = s end)
 
-    self._connection:send("ping", function()
+    self._connection:send("currentsong", function(_, s)
+        song = s
+        self._connection:albumart(song.file, function(_, art)
+            local info = {}
+            if art and art.binary then
+                info.icon = '/tmp/test.jpg'
+                local f = io.open(info.icon, 'w')
+                f:write(art.binary)
+                f:close()
+            end
 
-        local info = {}
-        info.title = status.state .. " " .. status.song .. "/" .. status.playlistlength .. " " .. song_duration(status.elapsed, status.duration)
-        if not song.artist then
-            info.text = string.format("%s", song.title or song.file)
-        else
-            info.text = string.format("%s - %s", song.artist, song.title)
-        end
-        if song.album then
-            info.text = info.text .. "\n" .. tostring(song.album or "")
-        end
-        callback(info)
+            info.title = status.state .. " " .. status.song .. "/" .. status.playlistlength .. " " .. song_duration(status.elapsed, status.duration)
+            if not song.artist then
+                info.text = string.format("%s", song.title or song.file)
+            else
+                info.text = string.format("%s - %s", song.artist, song.title)
+            end
+            if song.album then
+                info.text = info.text .. "\n" .. tostring(song.album or "")
+            end
+            callback(info)
+        end)
     end)
 end
 
@@ -71,7 +79,8 @@ function widget:popup_show()
         if self._notification then return end
         self._notification = naughty.notify(
             { title = table.title
-            -- , icon = img
+            , icon = table.icon
+            , icon_size = 64
             , text = table.text
             , timeout = 0
             , destroy = function() self._timer:stop(); self._notification = nil end