Compare commits
No commits in common. "4e4c6b3d6946ea3d112b83a349c7ee4408f3902d" and "f43eb60b935dc31f7c47635afd94a22034b3374b" have entirely different histories.
4e4c6b3d69
...
f43eb60b93
BIN
electricboogaloo
BIN
electricboogaloo
Binary file not shown.
38
image.go
38
image.go
|
@ -2,22 +2,18 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"image"
|
"image"
|
||||||
_ "image/gif"
|
_ "image/gif"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"golang.org/x/image/draw"
|
"golang.org/x/image/draw"
|
||||||
)
|
)
|
||||||
|
|
||||||
func retrieveArt(path string) ([]byte, error) {
|
func retrieveArt(path string) ([]byte, error) {
|
||||||
|
|
||||||
//streaming PC is primarily flacs, so flacs first, then mp3s, then check
|
//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.
|
||||||
//for covers in folder, finally just use a default image if none of the
|
|
||||||
//above exist.
|
|
||||||
switch {
|
switch {
|
||||||
case hasFlacTrackArt(path):
|
case hasFlacTrackArt(path):
|
||||||
return getFlacArt(path)
|
return getFlacArt(path)
|
||||||
|
@ -61,35 +57,3 @@ func writeArtFile(orig []byte) (string, error) {
|
||||||
}
|
}
|
||||||
return pathOut, nil
|
return pathOut, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processBGColor(path string) (float64, error) {
|
|
||||||
imageSize := 1
|
|
||||||
f, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
imgBuff := bytes.NewBuffer(f)
|
|
||||||
imgOrig, _, err := image.Decode(imgBuff)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
img := image.NewRGBA(image.Rect(0, 0, imageSize, imageSize))
|
|
||||||
|
|
||||||
draw.ApproxBiLinear.Scale(img, img.Rect, imgOrig, imgOrig.Bounds(), draw.Over, nil)
|
|
||||||
|
|
||||||
r, g, b, _ := img.At(0, 0).RGBA()
|
|
||||||
// convert from 32 bit color back into 8 bit color
|
|
||||||
// this is to undo x |= x << 8 each value goes through
|
|
||||||
// trust me it works bro. bro it works.
|
|
||||||
r &= r >> 8
|
|
||||||
g &= g >> 8
|
|
||||||
b &= b >> 8
|
|
||||||
//a &= a >> 8
|
|
||||||
// 25 becomes 0x19, 36 is close to 10% of 256
|
|
||||||
fmt.Printf("0x%02x %02x %02x %02x\n", 25, r, g, b)
|
|
||||||
// it wants it abgr for some reason
|
|
||||||
rgba := fmt.Sprintf("0x%02x%02x%02x%02x", 25, b, g, r)
|
|
||||||
rgbaInt, err := strconv.ParseInt(rgba, 0, 64)
|
|
||||||
return float64(rgbaInt), err
|
|
||||||
}
|
|
||||||
|
|
27
main.go
27
main.go
|
@ -12,10 +12,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
1. Transition effect when swapping songs
|
|
||||||
2. Has/Get code in parse could probably be done with an interface instead? (is it worth it?)
|
1. Color backdrop to album cover (some sort of sampling?)
|
||||||
3. Document functions
|
2. Transition effect when swapping songs
|
||||||
|
3. Has/Get code in parse could probably be done with an interface instead? (is it worth it?)
|
||||||
|
4. Document functions
|
||||||
*/
|
*/
|
||||||
var password string
|
var password string
|
||||||
|
|
||||||
|
@ -75,19 +77,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
art, err := retrieveArt(path)
|
art, err := retrieveArt(path)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
artFile, err := writeArtFile(art)
|
artFile, err := writeArtFile(art)
|
||||||
if err != nil {
|
|
||||||
log.Printf("could not parse the art file, using default.jpg unprocessed.")
|
|
||||||
artFile = "./default.jpg"
|
|
||||||
}
|
|
||||||
color, err := processBGColor(artFile)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Could not determine color, setting to default color.\n%v", err)
|
|
||||||
color = 0xff424242
|
|
||||||
}
|
|
||||||
for i := range scil.SceneItems {
|
for i := range scil.SceneItems {
|
||||||
if scil.SceneItems[i].SourceName == "Artist" {
|
if scil.SceneItems[i].SourceName == "Artist" {
|
||||||
updateItem(client, scil.SceneItems[i], artist, "text")
|
updateItem(client, scil.SceneItems[i], artist, "text")
|
||||||
|
@ -101,9 +91,6 @@ func main() {
|
||||||
if scil.SceneItems[i].SourceName == "Art" {
|
if scil.SceneItems[i].SourceName == "Art" {
|
||||||
updateItem(client, scil.SceneItems[i], artFile, "file")
|
updateItem(client, scil.SceneItems[i], artFile, "file")
|
||||||
}
|
}
|
||||||
if scil.SceneItems[i].SourceName == "Color" {
|
|
||||||
updateItem(client, scil.SceneItems[i], color, "color")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(time.Duration(sleepTime) * time.Second)
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||||
|
@ -111,7 +98,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value any, key string) {
|
func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value string, key string) {
|
||||||
params := inputs.NewSetInputSettingsParams().WithInputName(sI.SourceName).WithInputUuid(sI.SourceUuid)
|
params := inputs.NewSetInputSettingsParams().WithInputName(sI.SourceName).WithInputUuid(sI.SourceUuid)
|
||||||
params.InputSettings = make(map[string]any)
|
params.InputSettings = make(map[string]any)
|
||||||
params.InputSettings[key] = value
|
params.InputSettings[key] = value
|
||||||
|
|
Loading…
Reference in New Issue