private async Task <bool> ProcessLabels(ILambdaContext context, string jobId) { GetContentModerationResponse response = null; do { GetContentModerationRequest request = new GetContentModerationRequest { JobId = jobId, MaxResults = MaxResults, NextToken = response?.NextToken, SortBy = ContentModerationSortBy.TIMESTAMP }; response = await this.rekClient.GetContentModerationAsync(request).ConfigureAwait(false); if (!(response?.VideoMetadata.DurationMillis >= maxLength)) { continue; } context.Logger.LogLine($"video exceeds max allowed length of {TimeSpan.FromMilliseconds(maxLength).TotalMinutes}. The observed length of video is {TimeSpan.FromMilliseconds(response.VideoMetadata.DurationMillis).TotalMinutes}"); return(false); } while (response?.NextToken != null); return(true); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetContentModerationResponse response = new GetContentModerationResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("JobStatus", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.JobStatus = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ModerationLabels", targetDepth)) { var unmarshaller = new ListUnmarshaller <ContentModerationDetection, ContentModerationDetectionUnmarshaller>(ContentModerationDetectionUnmarshaller.Instance); response.ModerationLabels = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ModerationModelVersion", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ModerationModelVersion = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("NextToken", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.NextToken = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("StatusMessage", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.StatusMessage = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("VideoMetadata", targetDepth)) { var unmarshaller = VideoMetadataUnmarshaller.Instance; response.VideoMetadata = unmarshaller.Unmarshall(context); continue; } } return(response); }
private async Task <bool> ProcessLabels(ILambdaContext context, string jobId) { GetContentModerationResponse response = null; do { GetContentModerationRequest request = new GetContentModerationRequest { JobId = jobId, MaxResults = MaxResults, NextToken = response?.NextToken, SortBy = ContentModerationSortBy.TIMESTAMP }; response = await this.rekClient.GetContentModerationAsync(request).ConfigureAwait(false); return(response.ModerationLabels.Any(x => this.labels.Contains(x.ModerationLabel.Name) || this.labels.Contains(x.ModerationLabel.ParentName) && x.ModerationLabel.Confidence > 40)); } while (response?.NextToken != null); }