-
Notifications
You must be signed in to change notification settings - Fork 1
/
dvrClipExtraction.go
178 lines (148 loc) · 5.29 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
package wserest
import (
"strconv"
"strings"
"time"
"github.com/openfresh/wse-rest-library-go/entity/application/helper"
"github.com/openfresh/wse-rest-library-go/entity/base"
)
// DvrClipExtraction is DVR stores utility
type DvrClipExtraction struct {
wowza
}
// 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
}
// GetItem retrieves the information about a store/converter
func (d *DvrClipExtraction) GetItem(name string) (map[string]interface{}, error) {
d.setRestURI(d.baseURI + "/" + name)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, GET, "")
}
// 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
/*
* /// query params
* dvrConverterStartTime=[unix timestamp]
* dvrConverterEndTime=[unix-timestamp]
* dvrConverterOutputFilename=[outputfilename]
*
* @param $startTime is a unix timestamp
* @param $endTime is a unix timestamp
* @param $outputFileName is a string
*/
func (d *DvrClipExtraction) Convert(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, "")
}
// 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, "")
}
// 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, "")
}
// GetAll retrieves the list of DVR stores associated with this application instance
func (d *DvrClipExtraction) GetAll() (map[string]interface{}, error) {
d.setNoParams()
d.setRestURI(d.baseURI)
return d.sendRequest(d.preparePropertiesForRequest(), []base.Entity{}, GET, "")
}
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, "")
}