-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathscene.go
128 lines (111 loc) · 2.69 KB
/
scene.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"errors"
"fmt"
"strings"
"github.com/andreykaipov/goobs/api/requests/scenes"
studiomode "github.com/andreykaipov/goobs/api/requests/studio_mode"
"github.com/muesli/coral"
)
var (
sceneCmd = &coral.Command{
Use: "scene",
Short: "manage scenes",
Long: `The scene command manages scenes`,
RunE: nil,
}
currentSceneCmd = &coral.Command{
Use: "current",
Short: "Switch program to a different scene",
RunE: func(cmd *coral.Command, args []string) error {
if len(args) < 1 {
return errors.New("current requires a scene name as argument")
}
return setCurrentScene(strings.Join(args, " "))
},
}
listSceneCmd = &coral.Command{
Use: "list",
Short: "List all scene names",
RunE: func(cmd *coral.Command, args []string) error {
return listScenes()
},
}
getSceneCmd = &coral.Command{
Use: "get",
Short: "Get the current scene",
RunE: func(cmd *coral.Command, args []string) error {
return getScene()
},
}
previewSceneCmd = &coral.Command{
Use: "preview",
Short: "Switch preview to a different scene (studio mode must be enabled)",
RunE: func(cmd *coral.Command, args []string) error {
if len(args) < 1 {
return errors.New("preview requires a scene name as argument")
}
return setPreviewScene(strings.Join(args, " "))
},
}
switchSceneCmd = &coral.Command{
Use: "switch",
Short: "Switch program or preview in studio mode to a different scene",
RunE: func(cmd *coral.Command, args []string) error {
if len(args) < 1 {
return errors.New("switch requires a scene name as argument")
}
return switchScene(strings.Join(args, " "))
},
}
)
func listScenes() error {
r, err := client.Scenes.GetSceneList()
if err != nil {
return err
}
for _, v := range r.Scenes {
fmt.Println(v.Name)
}
return nil
}
func getScene() error {
r, err := client.Scenes.GetCurrentScene()
if err != nil {
return err
}
fmt.Println(r.Name)
return nil
}
func setCurrentScene(scene string) error {
r := scenes.SetCurrentSceneParams{
SceneName: scene,
}
_, err := client.Scenes.SetCurrentScene(&r)
return err
}
func setPreviewScene(scene string) error {
r := studiomode.SetPreviewSceneParams{
SceneName: scene,
}
_, err := client.StudioMode.SetPreviewScene(&r)
return err
}
func switchScene(scene string) error {
isStudioModeEnabled, err := IsStudioModeEnabled()
if err != nil {
return err
}
if isStudioModeEnabled {
return setPreviewScene(scene)
}
return setCurrentScene(scene)
}
func init() {
sceneCmd.AddCommand(currentSceneCmd)
sceneCmd.AddCommand(listSceneCmd)
sceneCmd.AddCommand(getSceneCmd)
sceneCmd.AddCommand(previewSceneCmd)
sceneCmd.AddCommand(switchSceneCmd)
rootCmd.AddCommand(sceneCmd)
}