Compare commits

..

No commits in common. "f89089b816a7dc0c38bcd14b1f2b3948035d199d" and "b8714becca9abf7f51e4db97b8ea07e4764d14d6" have entirely different histories.

6 changed files with 30 additions and 95 deletions

22
cmus.go
View File

@ -1,9 +1,9 @@
package main
import (
"fmt"
"os/exec"
"strings"
"os/exec"
"fmt"
)
func CmusRemoteOutput() ([]string, error) {
@ -17,22 +17,20 @@ func CmusRemoteOutput() ([]string, error) {
return resp, err
}
func getAttribute(input []string, prefix ...string) (string, error) {
func getAttribute(input []string, prefix string) (string, error) {
var attr string
// probably more efficent to simply parse first selected list of prefixes, but i'd prefer it be first prefix in the preferred order
for p := range prefix {
for i := range input {
has := strings.HasPrefix(input[i], prefix[p])
has := strings.HasPrefix(input[i], prefix)
if has {
attr = input[i]
attr, b := strings.CutPrefix(attr, prefix[p])
}
}
attr, b := strings.CutPrefix(attr, prefix)
if !b {
return "", fmt.Errorf("prefix \"%v\" in \"%v\" does not exist", prefix, attr)
return "", fmt.Errorf("did not find prefix \"%v\"", prefix)
}
return attr, nil
}
}
}
return "", fmt.Errorf("prefixes \"%v\" were not found", prefix)
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

View File

@ -1,59 +0,0 @@
package main
import (
"bytes"
"image"
_ "image/gif"
"image/jpeg"
_ "image/png"
"os"
"golang.org/x/image/draw"
)
func retrieveArt(path string) ([]byte, error) {
//streaming PC is primarily flacs, so flacs first, then mp3s, then check for covers in folder, finally just use a default image if none of the above exist.
switch {
case hasFlacTrackArt(path):
return getFlacArt(path)
case hasMp3TrackArt(path):
return getMP3Art(path)
case hasCoverArtFile(path):
return getCoverArtFile(path)
default:
return getDefaultArt()
}
}
func writeArtFile(orig []byte) (string, error) {
imageSize := 700
pathOut := "/run/user/1000/albumcover.jpg"
img := make([]byte, 0)
imgBuffIn, imgBuffOut := bytes.NewBuffer(orig), bytes.NewBuffer(img)
imgOrig, _, err := image.Decode(imgBuffIn)
if err != nil {
return "", err
}
f, err := os.Create(pathOut)
if err != nil {
return "", err
}
defer f.Close()
imgOut := image.NewRGBA(image.Rect(0, 0, imageSize, imageSize))
draw.ApproxBiLinear.Scale(imgOut, imgOut.Rect, imgOrig, imgOrig.Bounds(), draw.Over, nil)
err = jpeg.Encode(imgBuffOut, imgOut, nil)
if err != nil {
return "", err
}
_, err = f.Write(imgBuffOut.Bytes())
if err != nil {
return "", err
}
return pathOut, nil
}

26
main.go
View File

@ -27,7 +27,7 @@ func main() {
panic(err)
}
artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ")
artist, err := getAttribute(out, "tag artist ")
if err != nil {
panic(err)
}
@ -39,34 +39,30 @@ func main() {
if err != nil {
panic(err)
}
path, err := getAttribute(out, "file ")
if err != nil {
panic(err)
}
art, err := retrieveArt(path)
artFile, err := writeArtFile(art)
for i := range scil.SceneItems {
if scil.SceneItems[i].SourceName == "Artist" {
updateItem(client, scil.SceneItems[i], artist, "text")
updateTextItem(client, scil.SceneItems[i], artist)
}
if scil.SceneItems[i].SourceName == "Song" {
updateItem(client, scil.SceneItems[i], title, "text")
updateTextItem(client, scil.SceneItems[i], title)
}
if scil.SceneItems[i].SourceName == "Album" {
updateItem(client, scil.SceneItems[i], album, "text")
}
if scil.SceneItems[i].SourceName == "Art" {
updateItem(client, scil.SceneItems[i], artFile, "file")
updateTextItem(client, scil.SceneItems[i], album)
}
}
}
func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value string, key string) {
func updateTextItem(client *goobs.Client, sI *typedefs.SceneItem, text string) {
params := inputs.NewSetInputSettingsParams().WithInputName(sI.SourceName).WithInputUuid(sI.SourceUuid)
params.InputSettings = make(map[string]any)
params.InputSettings[key] = value
params.InputSettings["text"] = text
_, err := client.Inputs.SetInputSettings(params)
if err != nil {
log.Fatal(err)
}
}

View File

@ -65,8 +65,8 @@ func hasMp3TrackArt(s string) bool {
return false
}
func hasCoverArtFile(s string) bool {
exts := []string{".jpg", ".jpeg", ".png", ".gif"} // check all sane image types
func hasCoverJpg(s string) bool {
exts := []string{".jpg", ".jpeg", ".png", ".gif"} // 'hasCoverJpg' is a misnomer, check all sane image types
dir := filepath.Dir(s)
file, err := os.Open(dir)
if err != nil {
@ -117,7 +117,7 @@ func getMP3Art(s string) ([]byte, error) {
return nil, fmt.Errorf("no image found")
}
func getCoverArtFile(s string) ([]byte, error) {
func getCoverJpg(s string) ([]byte, error) {
exts := []string{".jpg", ".jpeg", ".png", ".gif"}
dir := filepath.Dir(s)
file, err := os.Open(dir)