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