add lrc plugin (#156)
* added lrc plugin to display lyrics of playing music * added a small demonstration * fixed the readme and added proper thumbnail * added a demo * trimmed up some deps and removed the demo --------- Co-authored-by: shin01221 <mohamed@madin372.com>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
noctalia.setUpdateInterval(300)
|
||||
|
||||
local fetching = false
|
||||
local mpdPlayer = "mpd"
|
||||
|
||||
noctalia.runAsync("playerctl -l 2>/dev/null", function(r)
|
||||
if r.exitCode == 0 then
|
||||
for name in r.stdout:gmatch("[^\n]+") do
|
||||
if name:match("^mpd%.") then
|
||||
mpdPlayer = name
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function update()
|
||||
if fetching then
|
||||
return
|
||||
end
|
||||
|
||||
if not noctalia.commandExists("lrc_tty") then
|
||||
return
|
||||
end
|
||||
|
||||
noctalia.runAsync("playerctl status --player " .. mpdPlayer .. " 2>/dev/null", function(r)
|
||||
if r.exitCode == 0 and r.stdout:gsub("%s+$", "") == "Playing" then
|
||||
fetchLyrics(mpdPlayer)
|
||||
return
|
||||
end
|
||||
noctalia.runAsync("playerctl status --player spotify 2>/dev/null", function(r2)
|
||||
if r2.exitCode == 0 and r2.stdout:gsub("%s+$", "") == "Playing" then
|
||||
fetchLyrics("spotify")
|
||||
return
|
||||
end
|
||||
barWidget.setText("")
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
function fetchLyrics(player)
|
||||
fetching = true
|
||||
|
||||
noctalia.runAsync("lrc_tty --raw --player " .. player, function(r)
|
||||
fetching = false
|
||||
|
||||
if r.exitCode == 0 then
|
||||
local text = r.stdout:gsub("%s+$", "")
|
||||
if #text > 0 and text ~= "(no lyrics)" then
|
||||
barWidget.setText("| " .. text)
|
||||
return
|
||||
end
|
||||
end
|
||||
barWidget.setText("")
|
||||
end,30000)
|
||||
end
|
||||
Reference in New Issue
Block a user