add playing/paused status
ci/woodpecker/push/woodpecker Pipeline was successful Details

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
1 changed files with 20 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
r "gitnet.fr/deblan/i3-blocks-go/rendering"
"os"
"os/exec"
"strings"
)
func GetMetadata(metadata string) string {
@ -26,12 +27,29 @@ func GetArtist() string {
return GetMetadata("xesam:artist")
}
func GetStatus() string {
output, _ := exec.Command("playerctl", "-p", "spotify", "status").Output()
return strings.Trim(string(output), "\n")
}
func main() {
status := GetStatus()
title := GetTitle()
artist := GetArtist()
stmt := ""
if title == "" {
if status == "Not available" {
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{
@ -49,7 +67,7 @@ func main() {
}
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)
fmt.Println(block)