i3-blocks-go/blocks/spotify/main.go
Simon Vieille 54f7d29d8a
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
add block spotify
2022-08-29 19:57:44 +02:00

57 lines
1,023 B
Go

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)
}