forked from muesli/obs-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudiomode.go
111 lines (94 loc) · 2.56 KB
/
studiomode.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
package main
import (
"fmt"
"strconv"
"github.com/andreykaipov/goobs/api/requests/transitions"
"github.com/andreykaipov/goobs/api/requests/ui"
"github.com/muesli/coral"
)
var (
studioModeCmd = &coral.Command{
Use: "studiomode",
Short: "manage studio mode",
Long: `The studiomode command manages the studio mode`,
RunE: nil,
}
disableStudioModeCmd = &coral.Command{
Use: "disable",
Short: "Disables the studio mode",
RunE: func(cmd *coral.Command, args []string) error {
return disableStudioMode()
},
}
enableStudioModeCmd = &coral.Command{
Use: "enable",
Short: "Enables the studio mode",
RunE: func(cmd *coral.Command, args []string) error {
return enableStudioMode()
},
}
studioModeStatusCmd = &coral.Command{
Use: "status",
Short: "Reports studio mode status",
RunE: func(cmd *coral.Command, args []string) error {
return studioModeStatus()
},
}
toggleStudioModeCmd = &coral.Command{
Use: "toggle",
Short: "Toggles the studio mode (enable/disable)",
RunE: func(cmd *coral.Command, args []string) error {
return toggleStudioMode()
},
}
transitionToProgramCmd = &coral.Command{
Use: "transition",
Short: "Transition to program",
RunE: func(cmd *coral.Command, args []string) error {
return transitionToProgram()
},
}
)
func setStudioModeEnabled(enabled bool) error {
_, err := client.Ui.SetStudioModeEnabled(&ui.SetStudioModeEnabledParams{StudioModeEnabled: &enabled})
return err
}
func disableStudioMode() error {
return setStudioModeEnabled(false)
}
func enableStudioMode() error {
return setStudioModeEnabled(true)
}
// Determine if the studio mode is currently enabled in OBS.
func IsStudioModeEnabled() (bool, error) {
r, err := client.Ui.GetStudioModeEnabled()
return r.StudioModeEnabled, err
}
func studioModeStatus() error {
isStudioModeEnabled, err := IsStudioModeEnabled()
if err != nil {
return err
}
fmt.Printf("Studio Mode: %s\n", strconv.FormatBool(isStudioModeEnabled))
return nil
}
func toggleStudioMode() error {
enabled, err := IsStudioModeEnabled()
if err != nil {
return err
}
err = setStudioModeEnabled(!enabled)
return err
}
func transitionToProgram() error {
_, err := client.Transitions.TriggerStudioModeTransition(&transitions.TriggerStudioModeTransitionParams{})
return err
}
func init() {
studioModeCmd.AddCommand(disableStudioModeCmd)
studioModeCmd.AddCommand(enableStudioModeCmd)
studioModeCmd.AddCommand(studioModeStatusCmd)
studioModeCmd.AddCommand(toggleStudioModeCmd)
studioModeCmd.AddCommand(transitionToProgramCmd)
rootCmd.AddCommand(studioModeCmd)
}