diff --git a/blocks/spotify/main.go b/blocks/spotify/main.go index e91d718..708542b 100644 --- a/blocks/spotify/main.go +++ b/blocks/spotify/main.go @@ -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)