more helpful errors

This commit is contained in:
Octopus Octopus 2025-02-24 13:34:24 -06:00
parent 357c3d787e
commit 5ba1cfd33c
2 changed files with 22 additions and 11 deletions

Binary file not shown.

33
main.go
View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"log"
"time"
@ -10,43 +11,51 @@ import (
"github.com/andreykaipov/goobs/api/typedefs"
)
/* TODO:
/*
TODO:
1. Set password with a flag instead of text in the code
3. Change Panic(err) to code that doesn't crash the program if it fails
4. Document functions
*/
var password string
func init() {
flag.StringVar(&password, "p", "", "your obs websocket password")
flag.Parse()
}
func main() {
// change this password lol!
sleepTime := 2.0
client, err := goobs.New("localhost:4455", goobs.WithPassword("lwihuN0OUVTMeCMM"))
sleepTime := 1.0
client, err := goobs.New("localhost:4455", goobs.WithPassword(password))
if err != nil {
panic(err)
log.Fatalf("Authentication failed, password %v absent or incorrect.", password)
}
defer client.Disconnect()
params := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus")
scil, err := client.SceneItems.GetSceneItemList(params)
if err != nil {
panic(err)
// 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.
log.Fatalf("Expecting a scene named \"cmus\", but the scene was not found.\n%v", err.Error())
}
out, err := CmusRemoteOutput()
if err != nil {
panic(err)
log.Fatalf("%v\nCmus is likely not running.", err.Error())
}
path, err := getAttribute(out, "file ")
if err != nil {
panic(err)
log.Fatal(err.Error())
}
var prevPath string
for {
out, err = CmusRemoteOutput()
if err != nil {
panic(err)
log.Fatalf("%v\nCmus is likely not running.", err.Error())
}
path, err = getAttribute(out, "file ")
if err != nil {
panic(err)
log.Fatal(err.Error())
}
if path != prevPath {
artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ")
@ -93,6 +102,8 @@ func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value string, key
params.InputSettings[key] = value
_, err := client.Inputs.SetInputSettings(params)
if err != nil {
// i should probably forcefully create the item element missing, but
// this is fine for personal use.
log.Fatal(err)
}
}