mirror of
https://github.com/elenapan/dotfiles.git
synced 2026-01-07 09:17:23 +08:00
Added spotify daemon and example spotify widget
Former-commit-id: c0cb2979b2
Former-commit-id: b49f80e039a49894ca2cd98679150fba4c091404
Former-commit-id: 785592b3bc72bebb2dad98c6f12ecaa514eaa206
Former-commit-id: 795b8b77c387b84fb24509fa97733a4b578df2d9
This commit is contained in:
parent
ddbbc18780
commit
3f7f93822e
3 changed files with 75 additions and 0 deletions
|
|
@ -8,5 +8,6 @@ require("evil.ram")
|
|||
require("evil.weather")
|
||||
require("evil.mpd")
|
||||
require("evil.brightness")
|
||||
require("evil.spotify")
|
||||
|
||||
-- return evil
|
||||
|
|
|
|||
32
config/awesome/evil/spotify.lua
Normal file
32
config/awesome/evil/spotify.lua
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-- 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)
|
||||
42
config/awesome/noodle/spotify.lua
Normal file
42
config/awesome/noodle/spotify.lua
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
local wibox = require("wibox")
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
|
||||
-- Declare widgets
|
||||
local spotify_artist = wibox.widget.textbox()
|
||||
local spotify_title = wibox.widget.textbox()
|
||||
|
||||
-- Main widget that includes all others
|
||||
local spotify_widget = wibox.widget {
|
||||
-- Title widget
|
||||
{
|
||||
align = "center",
|
||||
text = "---",
|
||||
font = "sans 14",
|
||||
widget = spotify_title
|
||||
},
|
||||
-- Artist widget
|
||||
{
|
||||
align = "center",
|
||||
text = "---",
|
||||
font = "sans 10",
|
||||
widget = spotify_artist
|
||||
},
|
||||
spacing = 2,
|
||||
layout = wibox.layout.fixed.vertical
|
||||
}
|
||||
|
||||
-- Subcribe to spotify updates
|
||||
awesome.connect_signal("evil::spotify", function(artist, title, status)
|
||||
-- Do whatever you want with artist, title, status
|
||||
-- ...
|
||||
spotify_artist.text = artist
|
||||
spotify_title.text = title
|
||||
|
||||
-- Example notification (might not be needed if spotify already sends one)
|
||||
if status == "playing" then
|
||||
naughty.notify({ title = "Spotify | Now Playing", message = title.." by "..artist })
|
||||
end
|
||||
end)
|
||||
|
||||
return spotify_widget
|
||||
Loading…
Add table
Add a link
Reference in a new issue