avoid unneccessary commands
This commit is contained in:
parent
9755424d5e
commit
31d2dbebec
18
main.go
18
main.go
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue