This commit is contained in:
parent
c0652db038
commit
54f7d29d8a
|
@ -9,6 +9,7 @@ Blocks compatible with [i3blocks](https://github.com/vivien/i3blocks).
|
||||||
* `tmux` for `app` and `date` blocks
|
* `tmux` for `app` and `date` blocks
|
||||||
* `df` for `du` block
|
* `df` for `du` block
|
||||||
* `xdg-open` for `du` block
|
* `xdg-open` for `du` block
|
||||||
|
* `playerctl` for `spotify` block
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -68,6 +69,12 @@ Show indicator of RSS.
|
||||||
rss <block_name> <feed_url> <feed_reader_url> <foreground_color_when_no_item> <foreground_color_when_items>
|
rss <block_name> <feed_url> <feed_reader_url> <foreground_color_when_no_item> <foreground_color_when_items>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Show current song played (spotify).
|
||||||
|
|
||||||
|
```
|
||||||
|
spotify
|
||||||
|
```
|
||||||
|
|
||||||
Show volume.
|
Show volume.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
56
blocks/spotify/main.go
Normal file
56
blocks/spotify/main.go
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
r "gitnet.fr/deblan/i3-blocks-go/rendering"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetMetadata(metadata string) string {
|
||||||
|
output, _ := exec.Command("playerctl", "-p", "spotify", "metadata", metadata).Output()
|
||||||
|
data := string(output)
|
||||||
|
|
||||||
|
if len(data) > 20 {
|
||||||
|
data = fmt.Sprintf("%s…", data[0:20])
|
||||||
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTitle() string {
|
||||||
|
return GetMetadata("xesam:title")
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetArtist() string {
|
||||||
|
return GetMetadata("xesam:artist")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
title := GetTitle()
|
||||||
|
artist := GetArtist()
|
||||||
|
|
||||||
|
if title == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
label := r.TextWithPadding(artist, r.FB{
|
||||||
|
Foreground: r.Color("grey1"),
|
||||||
|
Background: r.Color("black3"),
|
||||||
|
})
|
||||||
|
|
||||||
|
value := r.TextWithPadding(title, r.FB{
|
||||||
|
Foreground: r.Color("grey2"),
|
||||||
|
Background: r.Color("black1"),
|
||||||
|
})
|
||||||
|
|
||||||
|
if os.Getenv("BLOCK_BUTTON") == "1" {
|
||||||
|
exec.Command("i3-msg", `workspace "6. MEDIA"`).Output()
|
||||||
|
}
|
||||||
|
|
||||||
|
options := r.NewBlockOptions()
|
||||||
|
options.FullText = fmt.Sprintf("%s%s", label, value)
|
||||||
|
block := r.Block("spotify", options)
|
||||||
|
|
||||||
|
fmt.Println(block)
|
||||||
|
}
|
Loading…
Reference in a new issue