Skip to content

Commit 3ff1d46

Browse files
author
Francisco Souza
committed
provider/encodingcom: fix non-extended status unmarshaling
There's a top-level job when the status is extended. Thanks @marzagao :-D
1 parent edc046d commit 3ff1d46

File tree

3 files changed

+183
-68
lines changed

3 files changed

+183
-68
lines changed

data_test.go

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package encodingcom
2+
3+
const nonExtendedStatus = `{
4+
"response": {
5+
"id": "abc123",
6+
"userid": "myuser",
7+
"sourcefile": "http://some.video/file.mp4",
8+
"status": "Finished",
9+
"created": "2015-12-31 20:45:30",
10+
"started": "2015-12-31 20:45:34",
11+
"finished": "2015-12-31 21:00:03",
12+
"downloaded": "2015-12-31 20:45:32",
13+
"filesize": "379371262",
14+
"processor": "AMAZON",
15+
"region": "us-east-1",
16+
"time_left": "21",
17+
"progress": "100.0",
18+
"format": {
19+
"id": "f123",
20+
"status": "Finished",
21+
"created": "2015-12-31 20:45:30",
22+
"started": "2015-12-31 20:45:34",
23+
"finished": "2015-12-31 21:00:03",
24+
"output": "mp4",
25+
"output_preset": [],
26+
"destination": "s3://mynicebucket",
27+
"destination_status": "Saved",
28+
"protected_public_result": [],
29+
"size": "0x1080",
30+
"bitrate": "3500k",
31+
"audio_bitrate": "192k",
32+
"audio_sample_rate": "48000",
33+
"audio_channels_number": "2",
34+
"downmix_mode": "pl2",
35+
"framerate": "30",
36+
"framerate_upper_threshold": [],
37+
"fade_in": [],
38+
"fade_out": [],
39+
"crop_top": [],
40+
"crop_left": [],
41+
"crop_right": [],
42+
"crop_bottom": [],
43+
"padd_top": [],
44+
"padd_left": [],
45+
"padd_right": [],
46+
"padd_bottom": [],
47+
"set_aspect_ratio": [],
48+
"keep_aspect_ratio": "yes",
49+
"video_codec": "libx264",
50+
"profile": "high",
51+
"VCodecParameters": [],
52+
"video_codec_parameters": {
53+
"coder": "1",
54+
"flags": "+loop",
55+
"flags2": "+bpyramid+wpred+mixed_refs+dct8x8-fastpskip",
56+
"cmp": "+chroma",
57+
"partitions": "+parti8x8+parti4x4+partp8x8+partb8x8",
58+
"me_method": "umh",
59+
"subq": "7",
60+
"me_range": "16",
61+
"bf": "16",
62+
"keyint_min": "25",
63+
"sc_threshold": "40",
64+
"i_qfactor": "0.71",
65+
"b_strategy": "1",
66+
"qcomp": "0.6",
67+
"qmin": "10",
68+
"qmax": "51",
69+
"qdiff": "4",
70+
"directpred": "1",
71+
"level": "30",
72+
"refs": "4",
73+
"psy": "0"
74+
},
75+
"audio_codec": "dolby_aac",
76+
"two_pass": "no",
77+
"turbo": "no",
78+
"twin_turbo": "no",
79+
"cbr": "no",
80+
"hard_cbr": "no",
81+
"minrate": [],
82+
"maxrate": [],
83+
"bufsize": [],
84+
"audio_minrate": [],
85+
"audio_maxrate": [],
86+
"audio_bufsize": [],
87+
"rc_init_occupancy": [],
88+
"deinterlacing": "auto",
89+
"video_sync": "old",
90+
"keyframe": "300",
91+
"start": [],
92+
"finish": [],
93+
"duration": [],
94+
"audio_volume": "100",
95+
"audio_normalization": [],
96+
"dmg_alerts": [],
97+
"loudness_mode": [],
98+
"input_speech": [],
99+
"clipmode": [],
100+
"prolimiter_max_peak": [],
101+
"input_dialnorm": [],
102+
"adjust_gain_for_dialnorm": [],
103+
"dialnorm_threshold": [],
104+
"dc_repair": [],
105+
"phase_repair": [],
106+
"dmix_center_level": [],
107+
"dmix_center_level_ltrt": [],
108+
"dmix_center_level_loro": [],
109+
"dmix_surround_level": [],
110+
"dmix_surround_level_ltrt": [],
111+
"dmix_surround_level_loro": [],
112+
"audio_sync": [],
113+
"rotate": "def",
114+
"noise_reduction": [],
115+
"two_pass_decoding": [],
116+
"force_keyframes": [],
117+
"metadata_copy": "no",
118+
"strip_chapters": "no",
119+
"pix_format": "yuv420p",
120+
"pan": [],
121+
"encoder": "v1",
122+
"burnin_timecode": [],
123+
"copy_timestamps": "yes",
124+
"encryption": "no",
125+
"encryption_method": "aes-128-cbc",
126+
"encryption_key": [],
127+
"encryption_key_file": [],
128+
"encryption_iv": [],
129+
"encryption_password": [],
130+
"slices": [],
131+
"audio_stream": [],
132+
"file_extension": "mp4",
133+
"ftyp": [],
134+
"hint": "no",
135+
"extends": [],
136+
"set_rotate": "0",
137+
"copy_nielsen_metadata": "no",
138+
"nielsen_breakout_code": [],
139+
"nielsen_distributor_id": [],
140+
"drm": "no",
141+
"drm-content-id": [],
142+
"drm-common-key": [],
143+
"drm-license-server-url": [],
144+
"drm-license-server-cert": [],
145+
"drm-transport-cert": [],
146+
"drm-packager-credential": [],
147+
"drm-credential-pwd": [],
148+
"drm-policy-file": [],
149+
"convertedsize": "78544430",
150+
"queued": "",
151+
"converttime": "0"
152+
},
153+
"queue_time": "0"
154+
}
155+
}`

media_status.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ func (c *Client) GetStatus(mediaIDs []string, extended bool) ([]StatusResponse,
7373
}
7474

7575
var apiStatus []statusJSON
76-
rawData := m["response"]["job"]
76+
var rawData interface{}
77+
if extended {
78+
rawData = m["response"]["job"]
79+
} else {
80+
rawData = m["response"]
81+
}
7782
rawBytes, _ := json.Marshal(rawData)
7883
if _, ok := rawData.([]interface{}); ok {
7984
json.Unmarshal(rawBytes, &apiStatus)

media_status_test.go

+22-67
Original file line numberDiff line numberDiff line change
@@ -282,44 +282,7 @@ func (s *S) TestGetStatusMultiple(c *check.C) {
282282

283283
// Some data are only available when extended=no
284284
func (s *S) TestGetStatusNotExtended(c *check.C) {
285-
server, requests := s.startServer(`
286-
{
287-
"response": {
288-
"job": {
289-
"id": "abc123",
290-
"userid": "myuser",
291-
"sourcefile": "http://some.video/file.mp4",
292-
"status": "Finished",
293-
"notifyurl": "http://ping.me/please",
294-
"created": "2015-12-31 20:45:30",
295-
"started": "2015-12-31 20:45:34",
296-
"finished": "2015-12-31 21:00:03",
297-
"prevstatus": "Saving",
298-
"downloaded": "2015-12-31 20:45:32",
299-
"uploaded": "2015-12-31 20:59:54",
300-
"time_left": "0",
301-
"progress": "100",
302-
"time_left_current": "0",
303-
"progress_current": "100.0",
304-
"format": {
305-
"id": "f123",
306-
"status": "Finished",
307-
"created": "2015-12-31 20:45:30",
308-
"started": "2015-12-31 20:45:34",
309-
"finished": "2015-12-31 21:00:03",
310-
"s3_destination": "https://s3.amazonaws.com/not-really/valid.mp4",
311-
"cf_destination": "https://blablabla.cloudfront.net/not-valid.mp4",
312-
"destination": "s3://mynicebucket",
313-
"destination_status": "Saved",
314-
"size": "0x1080",
315-
"bitrate": "3500k",
316-
"video_codec": "libx264",
317-
"audio_codec": "dolby_aac",
318-
"output": "mp4"
319-
}
320-
}
321-
}
322-
}`)
285+
server, requests := s.startServer(nonExtendedStatus)
323286
defer server.Close()
324287

325288
client := Client{Endpoint: server.URL, UserID: "myuser", UserKey: "123"}
@@ -330,39 +293,31 @@ func (s *S) TestGetStatusNotExtended(c *check.C) {
330293
expectedStartDate, _ := time.Parse(dateTimeLayout, "2015-12-31 20:45:34")
331294
expectedFinishDate, _ := time.Parse(dateTimeLayout, "2015-12-31 21:00:03")
332295
expectedDownloadDate, _ := time.Parse(dateTimeLayout, "2015-12-31 20:45:32")
333-
expectedUploadDate, _ := time.Parse(dateTimeLayout, "2015-12-31 20:59:54")
334296
expected := []StatusResponse{
335297
{
336-
MediaID: "abc123",
337-
UserID: "myuser",
338-
SourceFile: "http://some.video/file.mp4",
339-
MediaStatus: "Finished",
340-
PreviousMediaStatus: "Saving",
341-
NotifyURL: "http://ping.me/please",
342-
CreateDate: expectedCreateDate,
343-
StartDate: expectedStartDate,
344-
FinishDate: expectedFinishDate,
345-
DownloadDate: expectedDownloadDate,
346-
UploadDate: expectedUploadDate,
347-
TimeLeft: "0",
348-
Progress: 100.0,
349-
TimeLeftCurrentJob: "0",
350-
ProgressCurrentJob: 100.0,
298+
MediaID: "abc123",
299+
UserID: "myuser",
300+
SourceFile: "http://some.video/file.mp4",
301+
MediaStatus: "Finished",
302+
CreateDate: expectedCreateDate,
303+
StartDate: expectedStartDate,
304+
FinishDate: expectedFinishDate,
305+
DownloadDate: expectedDownloadDate,
306+
TimeLeft: "21",
307+
Progress: 100.0,
351308
Formats: []FormatStatus{
352309
{
353-
ID: "f123",
354-
Status: "Finished",
355-
CreateDate: expectedCreateDate,
356-
StartDate: expectedStartDate,
357-
FinishDate: expectedFinishDate,
358-
S3Destination: "https://s3.amazonaws.com/not-really/valid.mp4",
359-
CFDestination: "https://blablabla.cloudfront.net/not-valid.mp4",
360-
Destinations: []DestinationStatus{{Name: "s3://mynicebucket", Status: "Saved"}},
361-
Size: "0x1080",
362-
Bitrate: "3500k",
363-
Output: "mp4",
364-
VideoCodec: "libx264",
365-
AudioCodec: "dolby_aac",
310+
ID: "f123",
311+
Status: "Finished",
312+
CreateDate: expectedCreateDate,
313+
StartDate: expectedStartDate,
314+
FinishDate: expectedFinishDate,
315+
Destinations: []DestinationStatus{{Name: "s3://mynicebucket", Status: "Saved"}},
316+
Size: "0x1080",
317+
Bitrate: "3500k",
318+
Output: "mp4",
319+
VideoCodec: "libx264",
320+
AudioCodec: "dolby_aac",
366321
},
367322
},
368323
},

0 commit comments

Comments
 (0)