-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrecording.go
158 lines (132 loc) · 3.28 KB
/
recording.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"fmt"
"os"
"strconv"
"github.com/dustin/go-humanize"
"github.com/muesli/coral"
)
var (
recordingCmd = &coral.Command{
Use: "recording",
Short: "manage recordings",
Long: `The recording command manages recordings`,
RunE: nil,
}
startStopRecordingCmd = &coral.Command{
Use: "toggle",
Short: "Toggle recording",
RunE: func(cmd *coral.Command, args []string) error {
return startStopRecording()
},
}
startRecordingCmd = &coral.Command{
Use: "start",
Short: "Starts recording",
RunE: func(cmd *coral.Command, args []string) error {
return startRecording()
},
}
stopRecordingCmd = &coral.Command{
Use: "stop",
Short: "Stops recording",
RunE: func(cmd *coral.Command, args []string) error {
return stopRecording()
},
}
pauseRecordingCmd = &coral.Command{
Use: "pause",
Short: "manage paused state",
}
enablePauseRecordingCmd = &coral.Command{
Use: "enable",
Short: "Pause recording",
RunE: func(cmd *coral.Command, args []string) error {
return pauseRecording()
},
}
resumePauseRecordingCmd = &coral.Command{
Use: "resume",
Short: "Resume recording",
RunE: func(cmd *coral.Command, args []string) error {
return resumeRecording()
},
}
togglePauseRecordingCmd = &coral.Command{
Use: "toggle",
Short: "Pause/resume recording",
RunE: func(cmd *coral.Command, args []string) error {
return pauseResumeRecording()
},
}
recordingStatusCmd = &coral.Command{
Use: "status",
Short: "Reports recording status",
RunE: func(cmd *coral.Command, args []string) error {
return recordingStatus()
},
}
)
func startStopRecording() error {
_, err := client.Recording.StartStopRecording()
return err
}
func startRecording() error {
_, err := client.Recording.StartRecording()
return err
}
func stopRecording() error {
_, err := client.Recording.StopRecording()
return err
}
func pauseRecording() error {
_, err := client.Recording.PauseRecording()
return err
}
func resumeRecording() error {
_, err := client.Recording.ResumeRecording()
return err
}
func pauseResumeRecording() error {
r, err := client.Recording.GetRecordingStatus()
if err != nil {
return err
}
if !r.IsRecording {
return fmt.Errorf("recording is not running")
}
if r.IsRecordingPaused {
return resumeRecording()
}
return pauseRecording()
}
func recordingStatus() error {
r, err := client.Recording.GetRecordingStatus()
if err != nil {
return err
}
fmt.Printf("Recording: %s\n", strconv.FormatBool(r.IsRecording))
if !r.IsRecording {
return nil
}
fmt.Printf("Paused: %s\n", strconv.FormatBool(r.IsRecordingPaused))
fmt.Printf("File: %s\n", r.RecordingFilename)
fmt.Printf("Timecode: %s\n", r.RecordTimecode)
st, err := os.Stat(r.RecordingFilename)
if err != nil {
return err
}
fmt.Printf("Filesize: %s\n", humanize.Bytes(uint64(st.Size())))
return nil
}
func init() {
pauseRecordingCmd.AddCommand(enablePauseRecordingCmd)
pauseRecordingCmd.AddCommand(resumePauseRecordingCmd)
pauseRecordingCmd.AddCommand(togglePauseRecordingCmd)
recordingCmd.AddCommand(startStopRecordingCmd)
recordingCmd.AddCommand(startRecordingCmd)
recordingCmd.AddCommand(stopRecordingCmd)
recordingCmd.AddCommand(pauseRecordingCmd)
recordingCmd.AddCommand(recordingStatusCmd)
rootCmd.AddCommand(recordingCmd)
}