avoid unneccessary commands

This commit is contained in:
Octopus Octopus 2024-03-13 22:57:11 -05:00
parent 9755424d5e
commit 31d2dbebec
2 changed files with 47 additions and 41 deletions

BIN
cmus2obs

Binary file not shown.

18
main.go
View File

@ -19,7 +19,6 @@ import (
_ "image/gif"
"image/jpeg"
_ "image/jpeg"
_ "image/png"
)
@ -29,10 +28,18 @@ const (
)
func main() {
prevFilepath := ""
for {
c := exec.Command("cmus-remote", "-Q")
o, _ := c.Output()
remoteResp := strings.Split(string(o), "\n")
filepath, err := getAttribute(remoteResp, "file ")
if err != nil {
log.Fatal(err.Error())
}
if filepath != prevFilepath {
//Album
album, err := getAttribute(remoteResp, "tag album ")
if err != nil {
@ -49,11 +56,7 @@ func main() {
title = "Unknown"
}
filepath, err := getAttribute(remoteResp, "file ")
if err != nil {
log.Fatal(err.Error())
}
// Image
img := make([]byte, 0)
if strings.HasSuffix(filepath, ".flac") {
img, err = getFlacArt(filepath)
@ -68,6 +71,7 @@ func main() {
} else {
img = defaultArt()
}
imgBuff := bytes.NewBuffer(img)
imgOrig, _, err := image.Decode(imgBuff)
@ -85,6 +89,8 @@ func main() {
writeTxt("SongTitle", title)
writeJpg("AlbumArt", img)
}
prevFilepath = filepath
time.Sleep(TIMER * time.Second)
}
}