-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathstream.go
95 lines (79 loc) · 1.87 KB
/
stream.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
package main
import (
"fmt"
"strconv"
"github.com/andreykaipov/goobs/api/requests/streaming"
"github.com/muesli/coral"
)
var (
streamCmd = &coral.Command{
Use: "stream",
Short: "manage streams",
Long: `The stream command manages streams`,
RunE: nil,
}
startStopStreamCmd = &coral.Command{
Use: "toggle",
Short: "Toggle streaming",
RunE: func(cmd *coral.Command, args []string) error {
return startStopStream()
},
}
startStreamCmd = &coral.Command{
Use: "start",
Short: "Starts streaming",
RunE: func(cmd *coral.Command, args []string) error {
return startStream()
},
}
stopStreamCmd = &coral.Command{
Use: "stop",
Short: "Stops streaming",
RunE: func(cmd *coral.Command, args []string) error {
return stopStream()
},
}
streamStatusCmd = &coral.Command{
Use: "status",
Short: "Reports streaming status",
RunE: func(cmd *coral.Command, args []string) error {
return streamStatus()
},
}
)
func startStopStream() error {
_, err := client.Streaming.StartStopStreaming(&streaming.StartStopStreamingParams{})
return err
}
func startStream() error {
_, err := client.Streaming.StartStreaming(&streaming.StartStreamingParams{})
return err
}
func stopStream() error {
_, err := client.Streaming.StopStreaming()
return err
}
func streamStatus() error {
r, err := client.Streaming.GetStreamingStatus()
if err != nil {
return err
}
fmt.Printf("Streaming: %s\n", strconv.FormatBool(r.Streaming))
if !r.Streaming {
return nil
}
fmt.Printf("Timecode: %s\n", r.StreamTimecode)
rs, err := client.Streaming.GetStreamSettings()
if err != nil {
return err
}
fmt.Printf("URL: %s\n", rs.Settings.Server)
return nil
}
func init() {
streamCmd.AddCommand(startStopStreamCmd)
streamCmd.AddCommand(startStreamCmd)
streamCmd.AddCommand(stopStreamCmd)
streamCmd.AddCommand(streamStatusCmd)
rootCmd.AddCommand(streamCmd)
}