add playing/paused status
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Simon Vieille 2022-08-29 22:11:24 +02:00
parent 37adfa721e
commit 196f1cf14e
Signed by: deblan
GPG key ID: 579388D585F70417

View file

@ -5,6 +5,7 @@ import (
r "gitnet.fr/deblan/i3-blocks-go/rendering" r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os" "os"
"os/exec" "os/exec"
"strings"
) )
func GetMetadata(metadata string) string { func GetMetadata(metadata string) string {
@ -26,12 +27,29 @@ func GetArtist() string {
return GetMetadata("xesam:artist") return GetMetadata("xesam:artist")
} }
func GetStatus() string {
output, _ := exec.Command("playerctl", "-p", "spotify", "status").Output()
return strings.Trim(string(output), "\n")
}
func main() { func main() {
status := GetStatus()
title := GetTitle() title := GetTitle()
artist := GetArtist() artist := GetArtist()
stmt := ""
if title == "" { if status == "Not available" {
return return
} else if status == "Paused" {
stmt = r.TextWithPadding(r.FontAwesome("\uf04c"), r.FB{
Background: r.Color("black3"),
})
} else if status == "Playing" {
stmt = r.TextWithPadding(r.FontAwesome("\uf04b"), r.FB{
Foreground: r.Color("green"),
Background: r.Color("black3"),
})
} }
label := r.TextWithPadding(artist, r.FB{ label := r.TextWithPadding(artist, r.FB{
@ -49,7 +67,7 @@ func main() {
} }
options := r.NewBlockOptions() options := r.NewBlockOptions()
options.FullText = fmt.Sprintf("%s%s", label, value) options.FullText = fmt.Sprintf("%s%s%s", stmt, label, value)
block := r.Block("spotify", options) block := r.Block("spotify", options)
fmt.Println(block) fmt.Println(block)