77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
r "gitnet.fr/deblan/i3-blocks-go/rendering"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
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 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 status == "Not available" {
|
|
return
|
|
} else if status == "Stopped" {
|
|
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{
|
|
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%s", stmt, label, value)
|
|
block := r.Block("spotify", options)
|
|
|
|
fmt.Println(block)
|
|
}
|