Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to goobs #8

Merged
merged 2 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions changetext.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"errors"

obsws "github.com/muesli/go-obs-websocket"
"github.com/andreykaipov/goobs/api/requests/sources"
"github.com/spf13/cobra"
)

Expand All @@ -19,30 +19,32 @@ var changeTextCmd = &cobra.Command{
}

func changeLabel(source string, text string) error {
req := obsws.NewGetTextFreetype2PropertiesRequest(source)
resp, err := req.SendReceive(*client)
p := sources.GetTextFreetype2PropertiesParams{
Source: source,
}

resp, err := client.Sources.GetTextFreetype2Properties(&p)
if err != nil {
return err
}

chreq := obsws.NewSetTextFreetype2PropertiesRequest(
source,
resp.Color1,
resp.Color2,
resp.CustomWidth,
resp.DropShadow,
resp.Font,
resp.FontFace,
resp.FontFlags,
resp.FontSize,
resp.FontStyle,
resp.FromFile,
resp.LogMode,
resp.Outline,
text,
resp.TextFile,
resp.WordWrap)
return chreq.Send(*client)
r := sources.SetTextFreetype2PropertiesParams{
Source: source,
Color1: resp.Color1,
Color2: resp.Color2,
CustomWidth: resp.CustomWidth,
DropShadow: resp.DropShadow,
Font: resp.Font,
FromFile: resp.FromFile,
LogMode: resp.LogMode,
Outline: resp.Outline,
Text: text,
TextFile: resp.TextFile,
WordWrap: resp.WordWrap,
}

_, err = client.Sources.SetTextFreetype2Properties(&r)
return err
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/muesli/obs-cli
go 1.13

require (
github.com/muesli/go-obs-websocket v0.0.0-20200216195805-501318ebaadb
github.com/andreykaipov/goobs v0.6.0
github.com/spf13/cobra v0.0.5
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/andreykaipov/goobs v0.6.0 h1:qTZBh8fw9HlwfqdLKAWUGhgPsPSiGEosQNrBFmlQPm0=
github.com/andreykaipov/goobs v0.6.0/go.mod h1:PsbaqYzrYfbPcXhzI/VltZRekmU8cw3ydCGvFYaUFZA=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/muesli/go-obs-websocket v0.0.0-20200216195805-501318ebaadb h1:35DbT3O0cuzwBeXnQDldxE7jVxQ0ILl4yYA/46GePZk=
github.com/muesli/go-obs-websocket v0.0.0-20200216195805-501318ebaadb/go.mod h1:t4I9P6qb9scyqjgUYi4fMGoA46+hB7SxeoJiXlPQM3Q=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
Expand Down
22 changes: 7 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"time"

obsws "github.com/muesli/go-obs-websocket"
"github.com/andreykaipov/goobs"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +17,7 @@ var (
Short: "obs-cli is a command-line remote control for OBS",
}

client *obsws.Client
client *goobs.Client
)

func main() {
Expand All @@ -30,7 +27,7 @@ func main() {
}

if client != nil {
client.Disconnect()
_ = client.Disconnect()
}
}

Expand All @@ -41,15 +38,10 @@ func init() {
}

func connectOBS() {
// disable obsws logging
obsws.Logger = log.New(ioutil.Discard, "", log.LstdFlags)

client = &obsws.Client{Host: host, Port: int(port)}
if err := client.Connect(); err != nil {
fmt.Println(err)
var err error
client, err = goobs.New(host + fmt.Sprintf(":%d", port))
if err != nil {
fmt.Println("error:", err)
os.Exit(1)
}

// Set the amount of time we can wait for a response.
obsws.SetReceiveTimeout(time.Second * 2)
}
13 changes: 6 additions & 7 deletions recording.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
obsws "github.com/muesli/go-obs-websocket"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -32,18 +31,18 @@ var (
)

func starStopRecording() error {
req := obsws.NewStartStopRecordingRequest()
return req.Send(*client)
_, err := client.Recording.StartStopRecording()
return err
}

func startRecording() error {
req := obsws.NewStartRecordingRequest()
return req.Send(*client)
_, err := client.Recording.StartRecording()
return err
}

func stopRecording() error {
req := obsws.NewStopRecordingRequest()
return req.Send(*client)
_, err := client.Recording.StopRecording()
return err
}

func init() {
Expand Down
58 changes: 28 additions & 30 deletions sceneitems.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"errors"
"fmt"

obsws "github.com/muesli/go-obs-websocket"
sceneitems "github.com/andreykaipov/goobs/api/requests/scene_items"
"github.com/andreykaipov/goobs/api/typedefs"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -55,20 +56,18 @@ var (
)

func listSceneItems(scene string) error {
req := obsws.NewGetSceneListRequest()
resp, err := req.SendReceive(*client)
resp, err := client.Scenes.GetSceneList()
if err != nil {
return err
}

for _, v := range resp.Scenes {
if v["name"] != scene {
if v.Name != scene {
continue
}

for _, s := range v["sources"].([]interface{}) {
src := s.(map[string]interface{})
fmt.Println(src["name"])
for _, s := range v.Sources {
fmt.Println(s.Name)
}
}

Expand All @@ -77,31 +76,27 @@ func listSceneItems(scene string) error {

func setSceneItemVisible(visible bool, scene string, items ...string) error {
for _, item := range items {
req := obsws.NewGetSceneItemPropertiesRequest(scene, item)
resp, err := req.SendReceive(*client)
p := sceneitems.GetSceneItemPropertiesParams{
Item: &typedefs.Item{Name: item},
SceneName: scene,
}
resp, err := client.SceneItems.GetSceneItemProperties(&p)
if err != nil {
return err
}

chreq := obsws.NewSetSceneItemPropertiesRequest(
scene,
item,
resp.PositionX,
resp.PositionY,
resp.PositionAlignment,
resp.Rotation,
resp.ScaleX,
resp.ScaleY,
resp.CropTop,
resp.CropBottom,
resp.CropLeft,
resp.CropRight,
visible,
resp.BoundsType,
resp.BoundsAlignment,
resp.BoundsX,
resp.BoundsY)
err = chreq.Send(*client)
r := sceneitems.SetSceneItemPropertiesParams{
SceneName: scene,
Item: &typedefs.Item{Name: item},
Bounds: resp.Bounds,
Crop: resp.Crop,
Position: resp.Position,
Rotation: resp.Rotation,
Scale: resp.Scale,
Visible: visible,
}

_, err = client.SceneItems.SetSceneItemProperties(&r)
if err != nil {
return err
}
Expand All @@ -112,8 +107,11 @@ func setSceneItemVisible(visible bool, scene string, items ...string) error {

func toggleSceneItem(scene string, items ...string) error {
for _, item := range items {
req := obsws.NewGetSceneItemPropertiesRequest(scene, item)
resp, err := req.SendReceive(*client)
p := sceneitems.GetSceneItemPropertiesParams{
Item: &typedefs.Item{Name: item},
SceneName: scene,
}
resp, err := client.SceneItems.GetSceneItemProperties(&p)
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"

obsws "github.com/muesli/go-obs-websocket"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -33,8 +32,7 @@ func listSources() error {
*/

{
req := obsws.NewGetSpecialSourcesRequest()
resp, err := req.SendReceive(*client)
resp, err := client.Sources.GetSpecialSources()
if err != nil {
return err
}
Expand Down
13 changes: 6 additions & 7 deletions stream.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
obsws "github.com/muesli/go-obs-websocket"
"github.com/andreykaipov/goobs/api/requests/streaming"
"github.com/spf13/cobra"
)

Expand All @@ -24,17 +24,16 @@ var (
)

func startStream() error {
m := make(map[string]interface{})
req := obsws.NewStartStreamingRequest(m, "", m, m, "", "", true, "", "")
return req.Send(*client)
_, err := client.Streaming.StartStreaming(&streaming.StartStreamingParams{})
return err
}

func stopStream() error {
req := obsws.NewStopStreamingRequest()
return req.Send(*client)
_, err := client.Streaming.StopStreaming()
return err
}

func init() {
// rootCmd.AddCommand(startStreamCmd)
rootCmd.AddCommand(startStreamCmd)
rootCmd.AddCommand(stopStreamCmd)
}
9 changes: 6 additions & 3 deletions switchscene.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"strings"

obsws "github.com/muesli/go-obs-websocket"
"github.com/andreykaipov/goobs/api/requests/scenes"
"github.com/spf13/cobra"
)

Expand All @@ -20,8 +20,11 @@ var switchSceneCmd = &cobra.Command{
}

func switchScene(scene string) error {
req := obsws.NewSetCurrentSceneRequest(scene)
return req.Send(*client)
r := scenes.SetCurrentSceneParams{
SceneName: scene,
}
_, err := client.Scenes.SetCurrentScene(&r)
return err
}

func init() {
Expand Down
10 changes: 7 additions & 3 deletions togglemute.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"errors"

obsws "github.com/muesli/go-obs-websocket"
"github.com/andreykaipov/goobs/api/requests/sources"
"github.com/spf13/cobra"
)

Expand All @@ -19,8 +19,12 @@ var toggleMuteCmd = &cobra.Command{
}

func toggleMute(source string) error {
req := obsws.NewToggleMuteRequest(source)
return req.Send(*client)
p := sources.ToggleMuteParams{
Source: source,
}

_, err := client.Sources.ToggleMute(&p)
return err
}

func init() {
Expand Down