From f8c02273484224b9133f77606f0016fb6cdaff4b Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Mon, 10 Aug 2020 21:30:14 +0100 Subject: [PATCH] awesome/mpd_widget: request albumart when getting info --- awesome/widgets/mpd_widget.lua | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/awesome/widgets/mpd_widget.lua b/awesome/widgets/mpd_widget.lua index b6cfec8..2c6ab78 100644 --- a/awesome/widgets/mpd_widget.lua +++ b/awesome/widgets/mpd_widget.lua @@ -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 -- 2.48.1