spotify config

This commit is contained in:
streetturtle 2019-05-03 20:28:50 -04:00
parent 51999cc3cb
commit 57ae9fef44
4 changed files with 107 additions and 53 deletions

View File

@ -1,9 +1,9 @@
# Spotify widget # Spotify widget
This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: ![screenshot](./spo-wid-1.png) and consists of two parts: This widget displays currently playing song on [Spotify for Linux](https://www.spotify.com/download/linux/) client: ![screenshot](./spo-wid-default.png) and consists of two parts:
- status icon which shows if music is currently playing - status icon which shows if music is currently playing
- artist and name of the current song playing - artist and name of the current song
## Controls ## Controls
@ -15,11 +15,42 @@ This widget displays currently playing song on [Spotify for Linux](https://www.s
Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder. Note that widget uses the Arc icon theme, so it should be [installed](https://github.com/horst3180/arc-icon-theme#installation) first under **/usr/share/icons/Arc/** folder.
## Customization
It is possible to customize widget by providing a table with all or some of the following config parameters:
| Name | Default | Description |
|---|---|---|
| `play_icon` | `/usr/share/icons/Arc/actions/24/player_play.png` | Play icon |
| `pause_icon` | `/usr/share/icons/Arc/actions/24/player_pause.png` | Pause icon |
| `font` | `Play 9`| Font |
### Example:
```lua
spotify_widget({
font = 'Ubuntu Mono 9',
play_icon = '/usr/share/icons/Papirus-Light/24x24/categories/spotify.svg',
pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg'
})
```
Gives following widget:
![screenshot](./spo-wid-custom.png)
## Installation ## Installation
First you need to have spotify CLI installed. Here is how you can do it (except widget part): [pavelmakhov.com/2016/02/awesome-wm-spotify](http://pavelmakhov.com/2016/02/awesome-wm-spotify) First you need to have spotify CLI installed, it uses dbus to communicate with spotify-client:
To use this widget clone repo under **~/.config/awesome/** and then add it in **rc.lua**: ```bash
git clone https://gist.github.com/fa6258f3ff7b17747ee3.git
cd ./fa6258f3ff7b17747ee3
chmod +x sp
sudo cp ./sp /usr/local/bin/
```
Then clone repo under **~/.config/awesome/** and add widget in **rc.lua**:
```lua ```lua
local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify") local spotify_widget = require("awesome-wm-widgets.spotify-widget.spotify")
@ -28,6 +59,13 @@ s.mytasklist, -- Middle widget
{ -- Right widgets { -- Right widgets
layout = wibox.layout.fixed.horizontal, layout = wibox.layout.fixed.horizontal,
... ...
spotify_widget, -- default
spotify_widget(),
-- customized
spotify_widget({
font = 'Ubuntu Mono 9',
play_icon = '/usr/share/icons/Papirus-Light/24x24/categories/spotify.svg',
pause_icon = '/usr/share/icons/Papirus-Dark/24x24/panel/spotify-indicator.svg'
}),
... ...
``` ```

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -14,59 +14,75 @@ local watch = require("awful.widget.watch")
local GET_SPOTIFY_STATUS_CMD = 'sp status' local GET_SPOTIFY_STATUS_CMD = 'sp status'
local GET_CURRENT_SONG_CMD = 'sp current-oneline' local GET_CURRENT_SONG_CMD = 'sp current-oneline'
local PATH_TO_ICONS = "/usr/share/icons/Arc"
local spotify_widget = wibox.widget { local spotify_widget = {}
{
id = "icon",
widget = wibox.widget.imagebox,
},
{
id = 'current_song',
widget = wibox.widget.textbox,
font = 'Play 9'
},
layout = wibox.layout.align.horizontal,
set_status = function(self, is_playing)
self.icon.image = PATH_TO_ICONS ..
(is_playing and "/actions/24/player_play.png"
or "/actions/24/player_pause.png")
end,
set_text = function(self, path)
self.current_song.markup = path
end,
}
local update_widget_icon = function(widget, stdout, _, _, _) local function worker(args)
stdout = string.gsub(stdout, "\n", "")
widget:set_status(stdout == 'Playing' and true or false)
end
local update_widget_text = function(widget, stdout, _, _, _) local args = args or {}
if string.find(stdout, 'Error: Spotify is not running.') ~= nil then
widget:set_text('') local play_icon = args.play_icon or '/usr/share/icons/Arc/actions/24/player_play.png'
widget:set_visible(false) local pause_icon = args.pause_icon or '/usr/share/icons/Arc/actions/24/player_pause.png'
else local font = args.font or 'Play 9'
widget:set_text(stdout)
widget:set_visible(true) spotify_widget = wibox.widget {
{
id = "icon",
widget = wibox.widget.imagebox,
},
{
id = 'current_song',
widget = wibox.widget.textbox,
font = font
},
layout = wibox.layout.align.horizontal,
set_status = function(self, is_playing)
self.icon.image = (is_playing and play_icon or pause_icon)
end,
set_text = function(self, path)
self.current_song.markup = path
end,
}
local update_widget_icon = function(widget, stdout, _, _, _)
stdout = string.gsub(stdout, "\n", "")
widget:set_status(stdout == 'Playing' and true or false)
end end
end
watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget) local update_widget_text = function(widget, stdout, _, _, _)
watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget) if string.find(stdout, 'Error: Spotify is not running.') ~= nil then
widget:set_text('')
--- Adds mouse controls to the widget: widget:set_visible(false)
-- - left click - play/pause else
-- - scroll up - play next song widget:set_text(stdout)
-- - scroll down - play previous song widget:set_visible(true)
spotify_widget:connect_signal("button::press", function(_, _, _, button) end
if (button == 1) then awful.spawn("sp play", false) -- left click
elseif (button == 4) then awful.spawn("sp next", false) -- scroll up
elseif (button == 5) then awful.spawn("sp prev", false) -- scroll down
end end
awful.spawn.easy_async(GET_SPOTIFY_STATUS_CMD, function(stdout, stderr, exitreason, exitcode)
update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode) watch(GET_SPOTIFY_STATUS_CMD, 1, update_widget_icon, spotify_widget)
watch(GET_CURRENT_SONG_CMD, 1, update_widget_text, spotify_widget)
--- Adds mouse controls to the widget:
-- - left click - play/pause
-- - scroll up - play next song
-- - scroll down - play previous song
spotify_widget:connect_signal("button::press", function(_, _, _, button)
if (button == 1) then
awful.spawn("sp play", false) -- left click
elseif (button == 4) then
awful.spawn("sp next", false) -- scroll up
elseif (button == 5) then
awful.spawn("sp prev", false) -- scroll down
end
awful.spawn.easy_async(GET_SPOTIFY_STATUS_CMD, function(stdout, stderr, exitreason, exitcode)
update_widget_icon(spotify_widget, stdout, stderr, exitreason, exitcode)
end)
end) end)
end)
return spotify_widget return spotify_widget
end
return setmetatable(spotify_widget, { __call = function(_, ...)
return worker(...)
end })