-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.go
63 lines (53 loc) · 1.15 KB
/
main.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
package main
import (
"fmt"
"net/http"
"os"
"github.com/andreykaipov/goobs"
"github.com/muesli/coral"
)
var (
host string
password string
port uint32
version string
rootCmd = &coral.Command{
Use: "obs-cli",
Short: "obs-cli is a command-line remote control for OBS",
}
client *goobs.Client
)
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
if client != nil {
_ = client.Disconnect()
}
}
func init() {
coral.OnInitialize(connectOBS)
rootCmd.PersistentFlags().StringVar(&host, "host", "localhost", "host to connect to")
rootCmd.PersistentFlags().StringVar(&password, "password", "", "password for connection")
rootCmd.PersistentFlags().Uint32VarP(&port, "port", "p", 4444, "port to connect to")
}
func getUserAgent() string {
userAgent := "obs-cli"
if version != "" {
userAgent += "/" + version
}
return userAgent
}
func connectOBS() {
var err error
client, err = goobs.New(
host+fmt.Sprintf(":%d", port),
goobs.WithPassword(password),
goobs.WithRequestHeader(http.Header{"User-Agent": []string{getUserAgent()}}),
)
if err != nil {
fmt.Println("error:", err)
os.Exit(1)
}
}