mirror of
https://github.com/elenapan/dotfiles.git
synced 2026-01-10 11:12:37 +08:00
Former-commit-id: c0cb2979b2
Former-commit-id: b49f80e039a49894ca2cd98679150fba4c091404
Former-commit-id: 785592b3bc72bebb2dad98c6f12ecaa514eaa206
Former-commit-id: 795b8b77c387b84fb24509fa97733a4b578df2d9
32 lines
1.1 KiB
Lua
32 lines
1.1 KiB
Lua
-- Provides:
|
|
-- evil::spotify
|
|
-- artist (string)
|
|
-- song (string)
|
|
-- status (string) [playing | paused | stopped]
|
|
local awful = require("awful")
|
|
|
|
local function emit_info(playerctl_output)
|
|
local artist = playerctl_output:match('artist_start(.*)title_start')
|
|
local title = playerctl_output:match('title_start(.*)status_start')
|
|
-- Use the lower case of status
|
|
local status = playerctl_output:match('status_start(.*)'):lower()
|
|
status = string.gsub(status, '^%s*(.-)%s*$', '%1')
|
|
|
|
awesome.emit_signal("evil::spotify", artist, title, status)
|
|
end
|
|
|
|
-- Sleeps until spotify changes state (pause/play/next/prev)
|
|
local spotify_script = [[
|
|
sh -c '
|
|
playerctl metadata --format 'artist_start{{artist}}title_start{{title}}status_start{{status}}' --follow
|
|
']]
|
|
|
|
-- Kill old playerctl process
|
|
awful.spawn.easy_async_with_shell("ps x | grep \"playerctl metadata\" | grep -v grep | awk '{print $1}' | xargs kill", function ()
|
|
-- Emit song info with each line printed
|
|
awful.spawn.with_line_callback(spotify_script, {
|
|
stdout = function(line)
|
|
emit_info(line)
|
|
end
|
|
})
|
|
end)
|