-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobs.go
159 lines (134 loc) · 4.92 KB
/
jobs.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
package zencoder
import (
"fmt"
)
type FileProgress struct {
Id int64 `json:"id,omitempty"`
State string `json:"state,omitempty"`
CurrentEvent string `json:"current_event,omitempty"`
CurrentEventProgress float64 `json:"current_event_progress,omitempty"`
OverallProgress float64 `json:"progress,omitempty"`
}
type JobProgress struct {
State string `json:"state,omitempty"`
JobProgress float64 `json:"progress,omitempty"`
InputProgress *FileProgress `json:"input,omitempty"`
OutputProgress []*FileProgress `json:"outputs,omitempty"`
}
// Response from CreateJob
type CreateJobResponse struct {
Id int64 `json:"id,omitempty"`
Test bool `json:"test,omitempty"`
Outputs []struct {
Id int64 `json:"id,omitempty"`
Label *string `json:"label,omitempty"`
Url string `json:"url,omitempty"`
} `json:"outputs,omitempty"`
}
// A MediaFile
type MediaFile struct {
Id int64 `json:"id,omitempty"`
Url string `json:"url,omitempty"`
Format string `json:"format,omitempty"`
State string `json:"state,omitempty"`
Test bool `json:"test,omitempty"`
Privacy bool `json:"privacy"`
Width int32 `json:"width,omitempty"`
Height int32 `json:"height,omitempty"`
FrameRate float64 `json:"frame_rate,omitempty"`
DurationInMs int32 `json:"duration_in_ms,omitempty"`
Channels string `json:"channels,omitempty"`
AudioCodec string `json:"audio_codec,omitempty"`
AudioBitrateInKbps int32 `json:"audio_bitrate_in_kbps,omitempty"`
AudioSampleRate int32 `json:"audio_sample_rate,omitempty"`
VideoCodec string `json:"video_codec,omitempty"`
VideoBitrateInKbps int32 `json:"video_bitrate_in_kbps,omitempty"`
TotalBitrateInKbps int32 `json:"total_bitrate_in_kbps,omitempty"`
MD5Checksum string `json:"md5_checksum,omitempty"`
ErrorMessage *string `json:"error_message,omitempty"`
ErrorClass *string `json:"error_class,omitempty"`
Label *string `json:"label,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
FinishedAt string `json:"finished_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
FileSizeInBytes int64 `json:"file_size_bytes,omitempty"`
}
type InputMediaFile struct {
MediaFile
FileSizeInBytes int64 `json:"file_size_in_bytes,omitempty"`
JobId int64 `json:"job_id,omitempty"`
}
type OutputMediaFile struct {
MediaFile
FileSizeInBytes int64 `json:"file_size_in_bytes,omitempty"`
JobId int64 `json:"job_id,omitempty"`
}
// A Thumbnail
type Thumbnail struct {
Id int64 `json:"id,omitempty"`
Url string `json:"url,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
// A Job
type Job struct {
Id int64 `json:"id,omitempty"`
PassThrough *string `json:"pass_through,omitempty"`
State string `json:"state,omitempty"`
InputMediaFile *MediaFile `json:"input_media_file,omitempty"`
Test bool `json:"test,omitempty"`
OutputMediaFiles []*MediaFile `json:"output_media_files,omitempty"`
Thumbnails []*Thumbnail `json:"thumbnails,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
FinishedAt string `json:"finished_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
SubmittedAt string `json:"submitted_at,omitempty"`
}
// Job Details wrapper
type JobDetails struct {
Job *Job `json:"job,omitempty"`
}
// Create a Job
func (z *Zencoder) CreateJob(settings *EncodingSettings) (*CreateJobResponse, error) {
var result CreateJobResponse
if err := z.post("jobs", settings, &result); err != nil {
return nil, err
}
return &result, nil
}
// List Jobs
func (z *Zencoder) ListJobs() ([]*JobDetails, error) {
var result []*JobDetails
if err := z.getBody("jobs.json", &result); err != nil {
return nil, err
}
return result, nil
}
// Get Job Details
func (z *Zencoder) GetJobDetails(id int64) (*JobDetails, error) {
var result JobDetails
if err := z.getBody(fmt.Sprintf("jobs/%d.json", id), &result); err != nil {
return nil, err
}
return &result, nil
}
// Job Progress
func (z *Zencoder) GetJobProgress(id int64) (*JobProgress, error) {
var result JobProgress
if err := z.getBody(fmt.Sprintf("jobs/%d/progress.json", id), &result); err != nil {
return nil, err
}
return &result, nil
}
// Resubmit a Job
func (z *Zencoder) ResubmitJob(id int64) error {
return z.putNoContent(fmt.Sprintf("jobs/%d/resubmit.json", id))
}
// Cancel a Job
func (z *Zencoder) CancelJob(id int64) error {
return z.putNoContent(fmt.Sprintf("jobs/%d/cancel.json", id))
}
// Finish a Live Job
func (z *Zencoder) FinishLiveJob(id int64) error {
return z.putNoContent(fmt.Sprintf("jobs/%d/finish", id))
}