by Robin at 20240501; fix upload fail video mod

This commit is contained in:
Leufolium 2024-05-01 01:54:47 +08:00
parent e2501b7022
commit aca9281087
1 changed files with 63 additions and 43 deletions

View File

@ -115,13 +115,21 @@ func handleVideoModeration(result *green20220302.VideoModerationResultResponseBo
audioResult := result.Data.AudioResult audioResult := result.Data.AudioResult
// 解析信息 // 解析信息
frameSummaries, isFramesPassed := buildFrameSummaries(frameResult.FrameSummarys) isFramesPassed := true
isAudioPassed := true
if frameResult != nil {
var frameSummaries []*dbstruct.FrameSummary
frameSummaries, isFramesPassed = buildFrameSummaries(frameResult.FrameSummarys)
frameDetails := buildFrameDetails(frameResult.Frames) frameDetails := buildFrameDetails(frameResult.Frames)
audioSummaries, isAudioPassed := buildAudioSummaries(audioResult.AudioSummarys) videomoderation.SetFrameSummaries(frameSummaries).SetFrameDetails(frameDetails)
audioDetails := buildAudioDetails(result.Data.AudioResult.SliceDetails)
videomoderation.FrameNum = frameResult.FrameNum videomoderation.FrameNum = frameResult.FrameNum
videomoderation.SetFrameSummaries(frameSummaries).SetFrameDetails(frameDetails).SetAudioSummaries(audioSummaries).SetAudioDetails(audioDetails) }
if audioResult != nil {
var audioSummaries []*dbstruct.AudioSummary
audioSummaries, isAudioPassed = buildAudioSummaries(audioResult.AudioSummarys)
audioDetails := buildAudioDetails(audioResult.SliceDetails)
videomoderation.SetAudioSummaries(audioSummaries).SetAudioDetails(audioDetails)
}
// 判定检测结果 // 判定检测结果
if isFramesPassed && isAudioPassed { if isFramesPassed && isAudioPassed {
@ -165,6 +173,7 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons
isPassed = true isPassed = true
frameSummaries = make([]*dbstruct.FrameSummary, 0) frameSummaries = make([]*dbstruct.FrameSummary, 0)
for _, summary := range summaries { for _, summary := range summaries {
if summary != nil {
frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{ frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{
Label: summary.Label, Label: summary.Label,
LabelSum: summary.LabelSum, LabelSum: summary.LabelSum,
@ -173,41 +182,48 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons
isPassed = false isPassed = false
} }
} }
}
return return
} }
func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFrames) (frameDetails []*dbstruct.FrameDetail) { func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFrames) (frameDetails []*dbstruct.FrameDetail) {
frameDetails = make([]*dbstruct.FrameDetail, 0) frameDetails = make([]*dbstruct.FrameDetail, 0)
for _, detail := range details { for _, detail := range details {
if detail != nil {
frameDetail := &dbstruct.FrameDetail{ frameDetail := &dbstruct.FrameDetail{
Offset: detail.Offset, Offset: detail.Offset,
} }
frameDetail.SetFrameServiceDetails(buildFrameServiceDetails(detail.Results)) frameDetail.SetFrameServiceDetails(buildFrameServiceDetails(detail.Results))
frameDetails = append(frameDetails, frameDetail) frameDetails = append(frameDetails, frameDetail)
} }
}
return return
} }
func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResults) (frameServiceDetails []*dbstruct.FrameServiceDetail) { func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResults) (frameServiceDetails []*dbstruct.FrameServiceDetail) {
frameServiceDetails = make([]*dbstruct.FrameServiceDetail, 0) frameServiceDetails = make([]*dbstruct.FrameServiceDetail, 0)
for _, detail := range details { for _, detail := range details {
if detail != nil {
frameServiceDetail := &dbstruct.FrameServiceDetail{ frameServiceDetail := &dbstruct.FrameServiceDetail{
Service: detail.Service, Service: detail.Service,
} }
frameServiceDetail.SetFrameLabelDetails(buildFrameLabelDetails(detail.Result)) frameServiceDetail.SetFrameLabelDetails(buildFrameLabelDetails(detail.Result))
frameServiceDetails = append(frameServiceDetails, frameServiceDetail) frameServiceDetails = append(frameServiceDetails, frameServiceDetail)
} }
}
return return
} }
func buildFrameLabelDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResultsResult) (frameLabelDetails []*dbstruct.FrameLabelDetail) { func buildFrameLabelDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResultsResult) (frameLabelDetails []*dbstruct.FrameLabelDetail) {
frameLabelDetails = make([]*dbstruct.FrameLabelDetail, 0) frameLabelDetails = make([]*dbstruct.FrameLabelDetail, 0)
for _, detail := range details { for _, detail := range details {
if detail != nil {
frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{ frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{
Confidence: detail.Confidence, Confidence: detail.Confidence,
Label: detail.Label, Label: detail.Label,
}) })
} }
}
return return
} }
@ -215,6 +231,7 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons
isPassed = true isPassed = true
audioSummaries = make([]*dbstruct.AudioSummary, 0) audioSummaries = make([]*dbstruct.AudioSummary, 0)
for _, summary := range summaries { for _, summary := range summaries {
if summary != nil {
audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{ audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{
Label: summary.Label, Label: summary.Label,
LabelSum: summary.LabelSum, LabelSum: summary.LabelSum,
@ -223,12 +240,14 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons
isPassed = false isPassed = false
} }
} }
}
return return
} }
func buildAudioDetails(details []*green20220302.VideoModerationResultResponseBodyDataAudioResultSliceDetails) (audioDetails []*dbstruct.AudioDetail) { func buildAudioDetails(details []*green20220302.VideoModerationResultResponseBodyDataAudioResultSliceDetails) (audioDetails []*dbstruct.AudioDetail) {
audioDetails = make([]*dbstruct.AudioDetail, 0) audioDetails = make([]*dbstruct.AudioDetail, 0)
for _, detail := range details { for _, detail := range details {
if detail != nil {
audioDetails = append(audioDetails, &dbstruct.AudioDetail{ audioDetails = append(audioDetails, &dbstruct.AudioDetail{
EndTime: detail.EndTime, EndTime: detail.EndTime,
EndTimestamp: detail.EndTimestamp, EndTimestamp: detail.EndTimestamp,
@ -242,6 +261,7 @@ func buildAudioDetails(details []*green20220302.VideoModerationResultResponseBod
Text: detail.Text, Text: detail.Text,
}) })
} }
}
return return
} }