Skip to content

Commit 52bf0c7

Browse files
author
wanjiewu
committed
add:解析回调body
1 parent 31ac8d6 commit 52bf0c7

File tree

2 files changed

+154
-1
lines changed

2 files changed

+154
-1
lines changed

ci_media.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,134 @@ type CreateMultiMediaJobsResult struct {
189189
JobsDetail []MediaProcessJobDetail `xml:"JobsDetail,omitempty"`
190190
}
191191

192+
type MediaProcessJobsNotifyBody struct {
193+
XMLName xml.Name `xml:"Response"`
194+
EventName string `xml:"EventName"`
195+
JobsDetail struct {
196+
Code string `xml:"Code"`
197+
CreationTime string `xml:"CreationTime"`
198+
EndTime string `xml:"EndTime"`
199+
Input struct {
200+
BucketId string `xml:"BucketId"`
201+
Object string `xml:"Object"`
202+
Region string `xml:"Region"`
203+
} `xml:"Input"`
204+
JobId string `xml:"JobId"`
205+
Message string `xml:"Message"`
206+
Operation struct {
207+
MediaInfo struct {
208+
Format struct {
209+
Text string `xml:",chardata"`
210+
Bitrate string `xml:"Bitrate"`
211+
Duration string `xml:"Duration"`
212+
FormatLongName string `xml:"FormatLongName"`
213+
FormatName string `xml:"FormatName"`
214+
NumProgram string `xml:"NumProgram"`
215+
NumStream string `xml:"NumStream"`
216+
Size string `xml:"Size"`
217+
StartTime string `xml:"StartTime"`
218+
} `xml:"Format"`
219+
Stream struct {
220+
Audio []struct {
221+
Bitrate string `xml:"Bitrate"`
222+
Channel string `xml:"Channel"`
223+
ChannelLayout string `xml:"ChannelLayout"`
224+
CodecLongName string `xml:"CodecLongName"`
225+
CodecName string `xml:"CodecName"`
226+
CodecTag string `xml:"CodecTag"`
227+
CodecTagString string `xml:"CodecTagString"`
228+
CodecTimeBase string `xml:"CodecTimeBase"`
229+
Duration string `xml:"Duration"`
230+
Index string `xml:"Index"`
231+
Language string `xml:"Language"`
232+
SampleFmt string `xml:"SampleFmt"`
233+
SampleRate string `xml:"SampleRate"`
234+
StartTime string `xml:"StartTime"`
235+
Timebase string `xml:"Timebase"`
236+
} `xml:"Audio"`
237+
Subtitle string `xml:"Subtitle"`
238+
Video []struct {
239+
AvgFps string `xml:"AvgFps"`
240+
Bitrate string `xml:"Bitrate"`
241+
CodecLongName string `xml:"CodecLongName"`
242+
CodecName string `xml:"CodecName"`
243+
CodecTag string `xml:"CodecTag"`
244+
CodecTagString string `xml:"CodecTagString"`
245+
CodecTimeBase string `xml:"CodecTimeBase"`
246+
Dar string `xml:"Dar"`
247+
Duration string `xml:"Duration"`
248+
Fps string `xml:"Fps"`
249+
HasBFrame string `xml:"HasBFrame"`
250+
Height string `xml:"Height"`
251+
Index string `xml:"Index"`
252+
Language string `xml:"Language"`
253+
Level string `xml:"Level"`
254+
NumFrames string `xml:"NumFrames"`
255+
PixFormat string `xml:"PixFormat"`
256+
Profile string `xml:"Profile"`
257+
RefFrames string `xml:"RefFrames"`
258+
Rotation string `xml:"Rotation"`
259+
Sar string `xml:"Sar"`
260+
StartTime string `xml:"StartTime"`
261+
Timebase string `xml:"Timebase"`
262+
Width string `xml:"Width"`
263+
} `xml:"Video"`
264+
} `xml:"Stream"`
265+
} `xml:"MediaInfo"`
266+
MediaResult struct {
267+
OutputFile struct {
268+
Bucket string `xml:"Bucket"`
269+
ObjectName string `xml:"ObjectName"`
270+
ObjectPrefix string `xml:"ObjectPrefix"`
271+
Region string `xml:"Region"`
272+
} `xml:"OutputFile"`
273+
} `xml:"MediaResult"`
274+
Output struct {
275+
Bucket string `xml:"Bucket"`
276+
Object string `xml:"Object"`
277+
Region string `xml:"Region"`
278+
} `xml:"Output"`
279+
TemplateId string `xml:"TemplateId"`
280+
TemplateName string `xml:"TemplateName"`
281+
} `xml:"Operation"`
282+
QueueId string `xml:"QueueId"`
283+
StartTime string `xml:"StartTime"`
284+
State string `xml:"State"`
285+
Tag string `xml:"Tag"`
286+
} `xml:"JobsDetail"`
287+
}
288+
289+
type WorkflowExecutionNotifyBody struct {
290+
XMLName xml.Name `xml:"Response"`
291+
EventName string `xml:"EventName"`
292+
WorkflowExecution struct {
293+
RunId string `xml:"RunId"`
294+
BucketId string `xml:"BucketId"`
295+
Object string `xml:"Object"`
296+
CosHeaders []struct {
297+
Key string `xml:"Key"`
298+
Value string `xml:"Value"`
299+
} `xml:"CosHeaders"`
300+
WorkflowId string `xml:"WorkflowId"`
301+
WorkflowName string `xml:"WorkflowName"`
302+
CreateTime string `xml:"CreateTime"`
303+
State string `xml:"State"`
304+
Tasks []struct {
305+
Type string `xml:"Type"`
306+
CreateTime string `xml:"CreateTime"`
307+
EndTime string `xml:"EndTime"`
308+
State string `xml:"State"`
309+
JobId string `xml:"JobId"`
310+
Name string `xml:"Name"`
311+
TemplateId string `xml:"TemplateId"`
312+
TemplateName string `xml:"TemplateName"`
313+
TranscodeTemplateId string `xml:"TranscodeTemplateId,omitempty"`
314+
TranscodeTemplateName string `xml:"TranscodeTemplateName,omitempty"`
315+
HdrMode string `xml:"HdrMode,omitempty"`
316+
} `xml:"Tasks"`
317+
} `xml:"WorkflowExecution"`
318+
}
319+
192320
func (s *CIService) CreateMultiMediaJobs(ctx context.Context, opt *CreateMultiMediaJobsOptions) (*CreateMultiMediaJobsResult, *Response, error) {
193321
var res CreateMultiMediaJobsResult
194322
sendOpt := sendOptions{

example/CI/media_process/media_process.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"encoding/xml"
56
"fmt"
67
"net/http"
78
"net/url"
@@ -322,9 +323,33 @@ func InvokeMultiTasks() {
322323
}
323324
}
324325

326+
func TaskNotifyCallback() {
327+
taskBody := "<Response><EventName>TaskFinish</EventName><JobsDetail><Code>Success</Code><CreationTime>2021-09-14T14:38:59+0800</CreationTime><EndTime>2021-09-14T14:39:59+0800</EndTime><Input><BucketId></BucketId><Object>e28ef88b61ed41b7a6ea76a8147f4f9e</Object><Region>ap-guangzhou</Region></Input><JobId>j7123e78c152611ec9e8c1ba6632b91a8</JobId><Message/><Operation><MediaInfo><Format><Bitrate>3775.738000</Bitrate><Duration>143.732000</Duration><FormatLongName>QuickTime / MOV</FormatLongName><FormatName>mov,mp4,m4a,3gp,3g2,mj2</FormatName><NumProgram>0</NumProgram><NumStream>2</NumStream><Size>67836813</Size><StartTime>0.000000</StartTime></Format><Stream><Audio><Bitrate>125.049000</Bitrate><Channel>2</Channel><ChannelLayout>stereo</ChannelLayout><CodecLongName>AAC (Advanced Audio Coding)</CodecLongName><CodecName>aac</CodecName><CodecTag>0x6134706d</CodecTag><CodecTagString>mp4a</CodecTagString><CodecTimeBase>1/44100</CodecTimeBase><Duration>143.730998</Duration><Index>1</Index><Language>und</Language><SampleFmt>fltp</SampleFmt><SampleRate>44100</SampleRate><StartTime>0.000000</StartTime><Timebase>1/44100</Timebase></Audio><Subtitle/><Video><AvgFps>25/1</AvgFps><Bitrate>3645.417000</Bitrate><CodecLongName>H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10</CodecLongName><CodecName>h264</CodecName><CodecTag>0x31637661</CodecTag><CodecTagString>avc1</CodecTagString><CodecTimeBase>1/12800</CodecTimeBase><Dar>9:16</Dar><Duration>143.680000</Duration><Fps>25.500000</Fps><HasBFrame>2</HasBFrame><Height>3412</Height><Index>0</Index><Language>und</Language><Level>51</Level><NumFrames>3592</NumFrames><PixFormat>yuv420p</PixFormat><Profile>High</Profile><RefFrames>1</RefFrames><Rotation>0.000000</Rotation><Sar>2559:2560</Sar><StartTime>0.000000</StartTime><Timebase>1/12800</Timebase><Width>1920</Width></Video></Stream></MediaInfo><MediaResult><OutputFile><Bucket></Bucket><ObjectName>f89f22f7a8be4f478434da58eb11d7da.mp4</ObjectName><ObjectPrefix/><Region>ap-guangzhou</Region></OutputFile></MediaResult><Output><Bucket></Bucket><Object>f89f22f7a8be4f478434da58eb11d7da.mp4</Object><Region>ap-guangzhou</Region></Output><TemplateId>t064fb9214850f49aaac44b5561a7b0b3b</TemplateId><TemplateName>MP4-FHD</TemplateName></Operation><QueueId>p6f358a37bf9442ad8f859db055cd0edb</QueueId><StartTime>2021-09-14T14:38:59+0800</StartTime><State>Success</State><Tag>Transcode</Tag></JobsDetail></Response>"
328+
var body cos.MediaProcessJobsNotifyBody
329+
err := xml.Unmarshal([]byte(taskBody), &body)
330+
if err != nil {
331+
fmt.Println(fmt.Sprintf("err:%v", err))
332+
} else {
333+
fmt.Println(fmt.Sprintf("body:%v", body))
334+
}
335+
}
336+
337+
func WorkflowExecutionNotifyCallback() {
338+
workflowExecutionBody := "<Response><EventName>WorkflowFinish</EventName><WorkflowExecution><RunId>i70ae991a152911ecb184525400a8700f</RunId><BucketId></BucketId><Object>62ddbc1245.mp4</Object><CosHeaders><Key>x-cos-meta-id</Key><Value>62ddbc1245</Value></CosHeaders><CosHeaders><Key>Content-Type</Key><Value>video/mp4</Value></CosHeaders><WorkflowId>w29ba54d02b7340dd9fb44eb5beb786b9</WorkflowId><WorkflowName></WorkflowName><CreateTime>2021-09-14 15:00:26+0800</CreateTime><State>Success</State><Tasks><Type>Transcode</Type><CreateTime>2021-09-14 15:00:27+0800</CreateTime><EndTime>2021-09-14 15:00:42+0800</EndTime><State>Success</State><JobId>j70bab192152911ecab79bba409874f7f</JobId><Name>Transcode_1607323983818</Name><TemplateId>t088613dea8d564a9ba7e6b02cbd5de877</TemplateId><TemplateName>HLS-FHD</TemplateName></Tasks></WorkflowExecution></Response>"
339+
var body cos.WorkflowExecutionNotifyBody
340+
err := xml.Unmarshal([]byte(workflowExecutionBody), &body)
341+
if err != nil {
342+
fmt.Println(fmt.Sprintf("err:%v", err))
343+
} else {
344+
fmt.Println(fmt.Sprintf("body:%v", body))
345+
}
346+
}
347+
325348
func main() {
326349
// InvokeSnapshotTask()
327350
// InvokeConcatTask()
328351
// InvokeTranscodeTask()
329-
InvokeMultiTasks()
352+
// InvokeMultiTasks()
353+
TaskNotifyCallback()
354+
WorkflowExecutionNotifyCallback()
330355
}

0 commit comments

Comments
 (0)