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