Compare commits

...

5 Commits

Author SHA1 Message Date
Octopus Octopus f43eb60b93 deduplicate numbers lol 2025-02-24 13:40:09 -06:00
Octopus Octopus cbeffb0738 reorganized import 2025-02-24 13:39:29 -06:00
Octopus Octopus 51c78bb82f todo updates 2025-02-24 13:39:22 -06:00
Octopus Octopus 5ba1cfd33c more helpful errors 2025-02-24 13:34:24 -06:00
Octopus Octopus 357c3d787e loop output 2025-02-24 13:08:32 -06:00
3 changed files with 73 additions and 40 deletions

Binary file not shown.

102
main.go
View File

@ -1,7 +1,9 @@
package main package main
import ( import (
"flag"
"log" "log"
"time"
"github.com/andreykaipov/goobs" "github.com/andreykaipov/goobs"
"github.com/andreykaipov/goobs/api/requests/inputs" "github.com/andreykaipov/goobs/api/requests/inputs"
@ -9,62 +11,90 @@ import (
"github.com/andreykaipov/goobs/api/typedefs" "github.com/andreykaipov/goobs/api/typedefs"
) )
/* TODO: /*
1. Set password with a flag instead of text in the code TODO:
2. Loop output
3. Change Panic(err) to code that doesn't crash the program if it fails 1. Color backdrop to album cover (some sort of sampling?)
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 4. Document functions
*/ */
var password string
func init() {
flag.StringVar(&password, "p", "", "your obs websocket password")
flag.Parse()
}
func main() { func main() {
// change this password lol! // change this password lol!
client, err := goobs.New("localhost:4455", goobs.WithPassword("lwihuN0OUVTMeCMM")) sleepTime := 1.0
client, err := goobs.New("localhost:4455", goobs.WithPassword(password))
if err != nil { if err != nil {
panic(err) log.Fatalf("Authentication failed, password %v absent or incorrect.", password)
} }
defer client.Disconnect() defer client.Disconnect()
params := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus") params := sceneitems.NewGetSceneItemListParams().WithSceneName("cmus")
scil, err := client.SceneItems.GetSceneItemList(params) scil, err := client.SceneItems.GetSceneItemList(params)
if err != nil { 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() out, err := CmusRemoteOutput()
if err != nil { if err != nil {
panic(err) log.Fatalf("%v\nCmus is likely not running.", err.Error())
}
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 ") path, err := getAttribute(out, "file ")
if err != nil { if err != nil {
panic(err) log.Fatal(err.Error())
} }
art, err := retrieveArt(path) var prevPath string
artFile, err := writeArtFile(art) for {
for i := range scil.SceneItems { out, err = CmusRemoteOutput()
if scil.SceneItems[i].SourceName == "Artist" { if err != nil {
updateItem(client, scil.SceneItems[i], artist, "text") log.Fatalf("%v\nCmus is likely not running.", err.Error())
} }
if scil.SceneItems[i].SourceName == "Song" { path, err = getAttribute(out, "file ")
updateItem(client, scil.SceneItems[i], title, "text") if err != nil {
log.Fatal(err.Error())
} }
if scil.SceneItems[i].SourceName == "Album" { if path != prevPath {
updateItem(client, scil.SceneItems[i], album, "text") artist, err := getAttribute(out, "tag artist ", "tag albumartist ", "tag composer ")
} if err != nil {
if scil.SceneItems[i].SourceName == "Art" { log.Printf("%v does not have an artist listed.", path)
updateItem(client, scil.SceneItems[i], artFile, "file") artist = "Unknown"
}
title, err := getAttribute(out, "tag title ")
if err != nil {
log.Printf("%v does not have an title listed.", path)
title = "Unknown"
}
album, err := getAttribute(out, "tag album ")
if err != nil {
log.Printf("%v does not have an album listed.", path)
album = "Single"
}
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")
}
}
} }
time.Sleep(time.Duration(sleepTime) * time.Second)
prevPath = path
} }
} }
@ -74,6 +104,8 @@ func updateItem(client *goobs.Client, sI *typedefs.SceneItem, value string, key
params.InputSettings[key] = value params.InputSettings[key] = value
_, err := client.Inputs.SetInputSettings(params) _, err := client.Inputs.SetInputSettings(params)
if err != nil { if err != nil {
// i should probably forcefully create the item element missing, but
// this is fine for personal use.
log.Fatal(err) log.Fatal(err)
} }
} }

View File

@ -1,15 +1,16 @@
package main package main
import ( import (
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings" "strings"
"github.com/bogem/id3v2/v2" "github.com/bogem/id3v2/v2"
"github.com/go-flac/flacpicture" "github.com/go-flac/flacpicture"
"github.com/go-flac/go-flac" "github.com/go-flac/go-flac"
"fmt"
"os"
"io"
"log"
"path/filepath"
) )
// has // has