diff --git a/library/contentaudit/video_moderation/handler.go b/library/contentaudit/video_moderation/handler.go index 902bdb16..8df4bf1b 100644 --- a/library/contentaudit/video_moderation/handler.go +++ b/library/contentaudit/video_moderation/handler.go @@ -115,13 +115,21 @@ func handleVideoModeration(result *green20220302.VideoModerationResultResponseBo audioResult := result.Data.AudioResult // 解析信息 - frameSummaries, isFramesPassed := buildFrameSummaries(frameResult.FrameSummarys) - frameDetails := buildFrameDetails(frameResult.Frames) - audioSummaries, isAudioPassed := buildAudioSummaries(audioResult.AudioSummarys) - audioDetails := buildAudioDetails(result.Data.AudioResult.SliceDetails) - - videomoderation.FrameNum = frameResult.FrameNum - videomoderation.SetFrameSummaries(frameSummaries).SetFrameDetails(frameDetails).SetAudioSummaries(audioSummaries).SetAudioDetails(audioDetails) + isFramesPassed := true + isAudioPassed := true + if frameResult != nil { + var frameSummaries []*dbstruct.FrameSummary + frameSummaries, isFramesPassed = buildFrameSummaries(frameResult.FrameSummarys) + frameDetails := buildFrameDetails(frameResult.Frames) + videomoderation.SetFrameSummaries(frameSummaries).SetFrameDetails(frameDetails) + videomoderation.FrameNum = frameResult.FrameNum + } + if audioResult != nil { + var audioSummaries []*dbstruct.AudioSummary + audioSummaries, isAudioPassed = buildAudioSummaries(audioResult.AudioSummarys) + audioDetails := buildAudioDetails(audioResult.SliceDetails) + videomoderation.SetAudioSummaries(audioSummaries).SetAudioDetails(audioDetails) + } // 判定检测结果 if isFramesPassed && isAudioPassed { @@ -165,12 +173,14 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons isPassed = true frameSummaries = make([]*dbstruct.FrameSummary, 0) for _, summary := range summaries { - frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{ - Label: summary.Label, - LabelSum: summary.LabelSum, - }) - if util.DerefString(summary.Label) != VideoModerationPassLabel { - isPassed = false + if summary != nil { + frameSummaries = append(frameSummaries, &dbstruct.FrameSummary{ + Label: summary.Label, + LabelSum: summary.LabelSum, + }) + if util.DerefString(summary.Label) != VideoModerationPassLabel { + isPassed = false + } } } return @@ -179,11 +189,13 @@ func buildFrameSummaries(summaries []*green20220302.VideoModerationResultRespons func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFrames) (frameDetails []*dbstruct.FrameDetail) { frameDetails = make([]*dbstruct.FrameDetail, 0) for _, detail := range details { - frameDetail := &dbstruct.FrameDetail{ - Offset: detail.Offset, + if detail != nil { + frameDetail := &dbstruct.FrameDetail{ + Offset: detail.Offset, + } + frameDetail.SetFrameServiceDetails(buildFrameServiceDetails(detail.Results)) + frameDetails = append(frameDetails, frameDetail) } - frameDetail.SetFrameServiceDetails(buildFrameServiceDetails(detail.Results)) - frameDetails = append(frameDetails, frameDetail) } return } @@ -191,11 +203,13 @@ func buildFrameDetails(details []*green20220302.VideoModerationResultResponseBod func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResults) (frameServiceDetails []*dbstruct.FrameServiceDetail) { frameServiceDetails = make([]*dbstruct.FrameServiceDetail, 0) for _, detail := range details { - frameServiceDetail := &dbstruct.FrameServiceDetail{ - Service: detail.Service, + if detail != nil { + frameServiceDetail := &dbstruct.FrameServiceDetail{ + Service: detail.Service, + } + frameServiceDetail.SetFrameLabelDetails(buildFrameLabelDetails(detail.Result)) + frameServiceDetails = append(frameServiceDetails, frameServiceDetail) } - frameServiceDetail.SetFrameLabelDetails(buildFrameLabelDetails(detail.Result)) - frameServiceDetails = append(frameServiceDetails, frameServiceDetail) } return } @@ -203,10 +217,12 @@ func buildFrameServiceDetails(details []*green20220302.VideoModerationResultResp func buildFrameLabelDetails(details []*green20220302.VideoModerationResultResponseBodyDataFrameResultFramesResultsResult) (frameLabelDetails []*dbstruct.FrameLabelDetail) { frameLabelDetails = make([]*dbstruct.FrameLabelDetail, 0) for _, detail := range details { - frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{ - Confidence: detail.Confidence, - Label: detail.Label, - }) + if detail != nil { + frameLabelDetails = append(frameLabelDetails, &dbstruct.FrameLabelDetail{ + Confidence: detail.Confidence, + Label: detail.Label, + }) + } } return } @@ -215,12 +231,14 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons isPassed = true audioSummaries = make([]*dbstruct.AudioSummary, 0) for _, summary := range summaries { - audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{ - Label: summary.Label, - LabelSum: summary.LabelSum, - }) - if util.DerefString(summary.Label) != AudioModerationPassLabel { - isPassed = false + if summary != nil { + audioSummaries = append(audioSummaries, &dbstruct.AudioSummary{ + Label: summary.Label, + LabelSum: summary.LabelSum, + }) + if util.DerefString(summary.Label) != AudioModerationPassLabel { + isPassed = false + } } } return @@ -229,18 +247,20 @@ func buildAudioSummaries(summaries []*green20220302.VideoModerationResultRespons func buildAudioDetails(details []*green20220302.VideoModerationResultResponseBodyDataAudioResultSliceDetails) (audioDetails []*dbstruct.AudioDetail) { audioDetails = make([]*dbstruct.AudioDetail, 0) for _, detail := range details { - audioDetails = append(audioDetails, &dbstruct.AudioDetail{ - EndTime: detail.EndTime, - EndTimestamp: detail.EndTimestamp, - Extend: detail.Extend, - Labels: detail.Labels, - RiskTips: detail.RiskTips, - RiskWords: detail.RiskWords, - Score: detail.Score, - StartTime: detail.StartTime, - StartTimestamp: detail.StartTimestamp, - Text: detail.Text, - }) + if detail != nil { + audioDetails = append(audioDetails, &dbstruct.AudioDetail{ + EndTime: detail.EndTime, + EndTimestamp: detail.EndTimestamp, + Extend: detail.Extend, + Labels: detail.Labels, + RiskTips: detail.RiskTips, + RiskWords: detail.RiskWords, + Score: detail.Score, + StartTime: detail.StartTime, + StartTimestamp: detail.StartTimestamp, + Text: detail.Text, + }) + } } return }