forked from openfresh/wse-rest-library-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdvrClipExtraction.go
360 lines (293 loc) · 10.7 KB
/
dvrClipExtraction.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
package wserest
import (
"strconv"
"strings"
"time"
"github.com/sebastien4/wse-rest-library-go/entity/application/helper"
"github.com/sebastien4/wse-rest-library-go/entity/base"
)
// DvrClipExtraction is DVR stores utility
type DvrClipExtraction struct {
wowza
}
// WSEDVRStores is struct for GetAll() DVR stores
type WSEDVRStores struct {
ServerName string `json:"serverName"`
Version string `json:"version"`
DVRConverterStoreSummary []WSEDVRStore `json:"dvrconverterstoresummary"`
}
// WSEDVRStore is struct for GetAll() DVR stores
type WSEDVRStore struct {
ID string `json:"name"`
Location string `json:"location"`
}
// WSEDVRConverter is struct for GetAll() DVR stores
type WSEDVRConverter struct {
ID string `json:"dvrStoreName"`
ServerName string `json:"serverName"`
Version string `json:"version"`
DVRConverterStore WSEDVRConverterStore `json:"DvrConverterStore"`
}
// WSEDVRConverterStore is struct for GetAll() DVR stores
type WSEDVRConverterStore struct {
DVRStoreName string `json:"dvrStoreName"`
AudioAvailable bool `json:"audioAvailable"`
VideoAvailable bool `json:"videoAvailable"`
IsLive bool `json:"isLive"`
DVRStartTime int64 `json:"dvrStartTime"`
DVREndTime int64 `json:"dvrEndTime"`
Duration int64 `json:"duration"`
UTCStart int64 `json:"utcStart"`
UTCEnd int64 `json:"utcEnd"`
OutputFilename string `json:"outputFilename"`
DVRConversionStatus WSEDVRConversionStatus `json:"conversionStatus"`
}
// WSEDVRConversionStatus is struct for GetAll() DVR stores
type WSEDVRConversionStatus struct {
StoreName string `json:"storeName"`
FileName string `json:"fileName"`
State string `json:"state"` // The possible states are STOPPED, INITIALIZING, RUNNING, SUCCESSFUL, and ERROR.
StatusCode string `json:"statusCode"`
ErrorStrings []string `json:"errorStrings"`
StartTime int64 `json:"startTime"`
EndTime int64 `json:"endTime"`
Duration int64 `json:"duration"`
CurrentChunk int64 `json:"currentChunk"`
ChunkCount int64 `json:"chunkCount"`
FileSize int64 `json:"fileSize"`
FileDuration int64 `json:"fileDuration"`
}
// NewDvrClipExtraction creates DvrClipExtraction object
func NewDvrClipExtraction(settings *helper.Settings, appName string, appInstance string) *DvrClipExtraction {
if appInstance == "" {
appInstance = "_definst_"
}
d := new(DvrClipExtraction)
d.init(settings)
d.baseURI = d.host() + "/servers/" + d.serverInstance() + "/vhosts/" + d.vHostInstance() + "/applications/" + appName + "/instances/" + appInstance + "/dvrstores"
return d
}
// Create creates a new DVR store
func (d *DvrClipExtraction) Create() (map[string]interface{}, error) {
d.setRestURI(d.baseURI)
response, err := d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, POST, "")
return response, err
}
// GetItemOld retrieves the information about a store/converter
func (d *DvrClipExtraction) GetItemOld(name string) (map[string]interface{}, error) {
d.setRestURI(d.baseURI + "/" + name)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, GET, "")
}
// GetItem retrieves the information about a store/converter
func (d *DvrClipExtraction) GetItem(name string) (WSEDVRConverter, error) {
d.setRestURI(d.baseURI + "/" + name)
var r WSEDVRConverter
err := d.sendRequestSeb(&r, d.preparePropertiesForRequest(), []base.Entity{}, GET, "")
return r, err
}
// ConvertGroup convert group
func (d *DvrClipExtraction) ConvertGroup(nameArr []string) (map[string]interface{}, error) {
d.setNoParams()
d.setRestURI(d.baseURI + "/actions/convert?dvrConverterStoreList=" + strings.Join(nameArr, ","))
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// Convert converts
func (d *DvrClipExtraction) Convert(name string, startTime int64, endTime int64, outputFolder, outputFileName string, debugEnabled bool) (map[string]interface{}, error) {
d.setNoParams()
query := ""
if startTime != 0 {
query += "dvrConverterStartTime=" + strconv.FormatInt(startTime, 10)
}
if endTime != 0 {
if query != "" {
query += "&"
}
query += "dvrConverterEndTime=" + strconv.FormatInt(endTime, 10)
}
if outputFolder != "" {
if query != "" {
query += "&"
}
query += "dvrConverterDefaultFileDestination=" + outputFolder
}
if outputFileName != "" {
if query != "" {
query += "&"
}
query += "dvrConverterOutputFilename=" + outputFileName
}
if query != "" {
query += "&"
}
query += "dvrConverterDebugConversions=" + strconv.FormatBool(debugEnabled)
if len(query) > 0 {
query = "?" + query
}
d.setRestURI(d.baseURI + "/" + name + "/actions/convert" + query)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// ClearCache clear cache
func (d *DvrClipExtraction) ClearCache() (map[string]interface{}, error) {
d.setRestURI(d.baseURI + "/actions/expire")
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// DebugConversions converts
func (d *DvrClipExtraction) DebugConversions(name string) (map[string]interface{}, error) {
d.setRestURI(d.baseURI + "/" + name + "/actions/convert?dvrConverterDebugConversions=true")
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// ConvertByDurationWithStartTime conver by duration with start time
func (d *DvrClipExtraction) ConvertByDurationWithStartTime(name string, startTime *time.Time, duration *time.Duration, outputFileName string) (map[string]interface{}, error) {
d.setNoParams()
query := ""
if startTime != nil {
query += "dvrConverterStartTime=" + strconv.FormatInt(startTime.Unix(), 10)
}
if duration != nil {
if query != "" {
query += "&"
}
query += "dvrConverterDuration=" + strconv.FormatInt(int64(*duration/time.Millisecond), 10)
}
if outputFileName != "" {
if query != "" {
query += "&"
}
query += "dvrConverterOutputFilename=" + outputFileName
}
if len(query) > 0 {
query = "?" + query
}
d.setRestURI(d.baseURI + "/" + name + "/actions/convert" + query)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// ConvertByDurationWithStartTimeSeb converts by duration with start time
func (d *DvrClipExtraction) ConvertByDurationWithStartTimeSeb(name string, startTime int64, duration int64, outputFileName string, debugEnabled bool) (map[string]interface{}, error) {
d.setNoParams()
query := ""
if startTime != 0 {
query += "dvrConverterStartTime=" + strconv.FormatInt(startTime, 10)
}
if duration != 0 {
if query != "" {
query += "&"
}
query += "dvrConverterDuration=" + strconv.FormatInt(duration, 10)
}
if outputFileName != "" {
if query != "" {
query += "&"
}
query += "dvrConverterOutputFilename=" + outputFileName
}
if query != "" {
query += "&"
}
query += "dvrConverterDebugConversions=" + strconv.FormatBool(debugEnabled)
if len(query) > 0 {
query = "?" + query
}
d.setRestURI(d.baseURI + "/" + name + "/actions/convert" + query)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// ConvertByDurationWithEndTime convert by duration with end time
func (d *DvrClipExtraction) ConvertByDurationWithEndTime(name string, endTime *time.Time, duration *time.Duration, outputFileName string) (map[string]interface{}, error) {
d.setNoParams()
query := ""
if endTime != nil {
query += "dvrConverterEndTime=" + strconv.FormatInt(endTime.Unix(), 10)
}
if duration != nil {
if query != "" {
query += "&"
}
query += "dvrConverterDuration=" + strconv.FormatInt(int64(*duration/time.Millisecond), 10)
}
if outputFileName != "" {
if query != "" {
query += "&"
}
query += "dvrConverterOutputFilename=" + outputFileName
}
if len(query) > 0 {
query = "?" + query
}
d.setRestURI(d.baseURI + "/" + name + "/actions/convert" + query)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// ConvertOld converts
func (d *DvrClipExtraction) ConvertOld(name string, startTime *time.Time, endTime *time.Time, outputFileName string) (map[string]interface{}, error) {
d.setNoParams()
query := ""
if startTime != nil {
query += "dvrConverterStartTime=" + strconv.FormatInt(startTime.Unix(), 10)
}
if endTime != nil {
if query != "" {
query += "&"
}
query += "dvrConverterEndTime=" + strconv.FormatInt(endTime.Unix(), 10)
}
if outputFileName != "" {
if query != "" {
query += "&"
}
query += "dvrConverterOutputFilename=" + outputFileName
}
if len(query) > 0 {
query = "?" + query
}
d.setRestURI(d.baseURI + "/" + name + "/actions/convert" + query)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// ConvertByDurationWithEndTimeSeb convert by duration with end time
func (d *DvrClipExtraction) ConvertByDurationWithEndTimeSeb(name string, endTime int64, duration int64, outputFileName string, debugEnabled bool) (map[string]interface{}, error) {
d.setNoParams()
query := ""
if endTime != 0 {
query += "dvrConverterEndTime=" + strconv.FormatInt(endTime, 10)
}
if duration != 0 {
if query != "" {
query += "&"
}
query += "dvrConverterDuration=" + strconv.FormatInt(duration, 10)
}
if outputFileName != "" {
if query != "" {
query += "&"
}
query += "dvrConverterOutputFilename=" + outputFileName
}
if query != "" {
query += "&"
}
query += "dvrConverterDebugConversions=" + strconv.FormatBool(debugEnabled)
if len(query) > 0 {
query = "?" + query
}
d.setRestURI(d.baseURI + "/" + name + "/actions/convert" + query)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, PUT, "")
}
// GetAllOld retrieves the list of DVR stores associated with this application instance
func (d *DvrClipExtraction) GetAllOld() (map[string]interface{}, error) {
d.setNoParams()
d.setRestURI(d.baseURI)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, GET, "")
}
// GetAll retrieves the list of Applications
func (d *DvrClipExtraction) GetAll() (WSEDVRStores, error) {
d.setNoParams()
d.setRestURI(d.baseURI)
var r WSEDVRStores
err := d.sendRequestSeb(&r, d.preparePropertiesForRequest(), []base.Entity{}, GET, "")
return r, err
}
func (d *DvrClipExtraction) setNoParams() {
}
// Remove delete DVR store
func (d *DvrClipExtraction) Remove(fileName string) (map[string]interface{}, error) {
d.setNoParams()
d.setRestURI(d.baseURI + "/" + fileName)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, DELETE, "")
}