Compare commits

..

No commits in common. "f70b1726ccfd59478dc73645ac0d5cb4e01f01bf" and "4e4c6b3d6946ea3d112b83a349c7ee4408f3902d" have entirely different histories.

3 changed files with 27 additions and 54 deletions

Binary file not shown.

View File

@ -87,8 +87,7 @@ func processBGColor(path string) (float64, error) {
b &= b >> 8 b &= b >> 8
//a &= a >> 8 //a &= a >> 8
// 25 becomes 0x19, 36 is close to 10% of 256 // 25 becomes 0x19, 36 is close to 10% of 256
//fmt.Printf("0x%02x %02x %02x %02x\n", 25, r, g, b) fmt.Printf("0x%02x %02x %02x %02x\n", 25, r, g, b)
// it wants it abgr for some reason // it wants it abgr for some reason
rgba := fmt.Sprintf("0x%02x%02x%02x%02x", 25, b, g, r) rgba := fmt.Sprintf("0x%02x%02x%02x%02x", 25, b, g, r)
rgbaInt, err := strconv.ParseInt(rgba, 0, 64) rgbaInt, err := strconv.ParseInt(rgba, 0, 64)

78
main.go
View File

@ -2,7 +2,6 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"time" "time"
@ -14,8 +13,9 @@ import (
/* /*
TODO: TODO:
1. Scene transition is jumpy sometimes, probably doesn't like the 'cmus' scene changing while the scene item 'cmus' in 'streaming' is mid transition. (add a delay?) 1. Transition effect when swapping songs
1. Document functions 2. Has/Get code in parse could probably be done with an interface instead? (is it worth it?)
3. Document functions
*/ */
var password string var password string
@ -25,42 +25,39 @@ func init() {
} }
func main() { func main() {
// change this password lol!
sleepTime := 1.0 sleepTime := 1.0
client, err := goobs.New("localhost:4455", goobs.WithPassword(password)) client, err := goobs.New("localhost:4455", goobs.WithPassword(password))
if err != nil { if err != nil {
log.Fatalf("Authentication failed, password %v absent or incorrect.", password) log.Fatalf("Authentication failed, password %v absent or incorrect.", password)
} }
defer client.Disconnect() defer client.Disconnect()
cmusParams := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus") params := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus")
streamParams := sceneitems.NewGetSceneItemListParams().WithSceneName("stream") scil, err := client.SceneItems.GetSceneItemList(params)
cmusSCIL, err := client.SceneItems.GetSceneItemList(cmusParams)
if err != nil { if err != nil {
// i should force create the scene if it does not exist. but this is solely for me. // i should force create the scene if it does not exist. but this is solely for me.
// failing in this way is probably smarter since it forces to arrange the scene how i want it. // failing in this way is probably smarter since it forces to arrange the scene how i want it.
log.Fatalf("Expecting a scene named \"cmus\", but the scene was not found.\n%v", err.Error()) log.Fatalf("Expecting a scene named \"cmus\", but the scene was not found.\n%v", err.Error())
} }
streamSCIL, err := client.SceneItems.GetSceneItemList(streamParams) out, err := CmusRemoteOutput()
if err != nil { if err != nil {
log.Fatalf("Expecting a scene named \"stream\", but the scene was not found.\n%v", err.Error()) log.Fatalf("%v\nCmus is likely not running.", err.Error())
}
path, err := getAttribute(out, "file ")
if err != nil {
log.Fatal(err.Error())
} }
var prevPath string var prevPath string
for { for {
out, err := CmusRemoteOutput() out, err = CmusRemoteOutput()
if err != nil { if err != nil {
log.Fatalf("%v\nCmus is likely not running.", err.Error()) log.Fatalf("%v\nCmus is likely not running.", err.Error())
} }
path, err := getAttribute(out, "file ") path, err = getAttribute(out, "file ")
if err != nil { if err != nil {
log.Fatal(err.Error()) log.Fatal(err.Error())
} }
if path != prevPath { if path != prevPath {
//stream scene
for _, sI := range streamSCIL.SceneItems {
if sI.SourceName == "cmus" {
enableItem(client, "stream", sI, false)
}
}
//cmus scene
artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ") artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ")
if err != nil { if err != nil {
log.Printf("%v does not have an artist listed.", path) log.Printf("%v does not have an artist listed.", path)
@ -76,6 +73,7 @@ func main() {
log.Printf("%v does not have an album listed.", path) log.Printf("%v does not have an album listed.", path)
album = "Single" album = "Single"
} }
art, err := retrieveArt(path) art, err := retrieveArt(path)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -90,27 +88,21 @@ func main() {
log.Printf("Could not determine color, setting to default color.\n%v", err) log.Printf("Could not determine color, setting to default color.\n%v", err)
color = 0xff424242 color = 0xff424242
} }
for _, sI := range cmusSCIL.SceneItems { for i := range scil.SceneItems {
if sI.SourceName == "Artist" { if scil.SceneItems[i].SourceName == "Artist" {
updateItem(client, sI, artist, "text") updateItem(client, scil.SceneItems[i], artist, "text")
} }
if sI.SourceName == "Song" { if scil.SceneItems[i].SourceName == "Song" {
updateItem(client, sI, title, "text") updateItem(client, scil.SceneItems[i], title, "text")
} }
if sI.SourceName == "Album" { if scil.SceneItems[i].SourceName == "Album" {
updateItem(client, sI, album, "text") updateItem(client, scil.SceneItems[i], album, "text")
} }
if sI.SourceName == "Art" { if scil.SceneItems[i].SourceName == "Art" {
updateItem(client, sI, artFile, "file") updateItem(client, scil.SceneItems[i], artFile, "file")
} }
if sI.SourceName == "Color" { if scil.SceneItems[i].SourceName == "Color" {
updateItem(client, sI, color, "color") updateItem(client, scil.SceneItems[i], color, "color")
}
}
// stream scene
for _, sI := range streamSCIL.SceneItems {
if sI.SourceName == "cmus" {
enableItem(client, "stream", sI, true)
} }
} }
} }
@ -130,21 +122,3 @@ func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value any, key str
log.Fatal(err) log.Fatal(err)
} }
} }
func enableItem(client *goobs.Client, sceneName string, sI *typedefs.SceneItem, enabled bool) {
params := sceneitems.NewSetSceneItemEnabledParams().WithSceneName(sceneName).WithSceneUuid(sI.SourceUuid).WithSceneItemId(sI.SceneItemID).WithSceneItemEnabled(enabled)
_, err := client.SceneItems.SetSceneItemEnabled(params)
if err != nil {
log.Printf("could not set %v to %v.\n%v\n", sI.SourceName, enabled, err)
}
}
func getItemSettings(client *goobs.Client, sI *typedefs.SceneItem) {
params := inputs.NewGetInputSettingsParams().WithInputName(sI.SourceName).WithInputUuid(sI.SourceUuid)
gis, err := client.Inputs.GetInputSettings(params)
if err != nil {
// this is a helper function, it should not be running usually. this is fine for debugging/development
log.Fatal(err)
}
fmt.Printf("%v\n", gis)
}