73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/andreykaipov/goobs"
|
|
"github.com/andreykaipov/goobs/api/requests/inputs"
|
|
"github.com/andreykaipov/goobs/api/requests/sceneitems"
|
|
"github.com/andreykaipov/goobs/api/typedefs"
|
|
)
|
|
|
|
func main() {
|
|
// change this password lol!
|
|
client, err := goobs.New("localhost:4455", goobs.WithPassword("lwihuN0OUVTMeCMM"))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer client.Disconnect()
|
|
params := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus")
|
|
scil, err := client.SceneItems.GetSceneItemList(params)
|
|
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
out, err := CmusRemoteOutput()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
title, err := getAttribute(out, "tag title ")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
album, err := getAttribute(out, "tag album ")
|
|
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")
|
|
}
|
|
if scil.SceneItems[i].SourceName == "Song" {
|
|
updateItem(client, scil.SceneItems[i], title, "text")
|
|
}
|
|
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")
|
|
}
|
|
}
|
|
}
|
|
|
|
func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value string, key string) {
|
|
params := inputs.NewSetInputSettingsParams().WithInputName(sI.SourceName).WithInputUuid(sI.SourceUuid)
|
|
params.InputSettings = make(map[string]any)
|
|
params.InputSettings[key] = value
|
|
_, err := client.Inputs.SetInputSettings(params)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|