Exemple #1
0
        public async Task <string> CreateVideoReviewInContentModerator(UploadAssetResult uploadAssetResult)
        {
            string reviewId = string.Empty;
            List <ProcessedFrameDetails> frameEntityList = framegenerator.CreateVideoFrames(uploadAssetResult);
            string path = uploadAssetResult.GenerateVTT == true ? this._amsConfig.FfmpegFramesOutputPath + Path.GetFileNameWithoutExtension(uploadAssetResult.VideoName) + "_aud_SpReco.vtt" : "";
            TranscriptScreenTextResult screenTextResult = new TranscriptScreenTextResult();

            if (File.Exists(path))
            {
                screenTextResult = await GenerateTextScreenProfanity(reviewId, path, frameEntityList);

                uploadAssetResult.Category1TextScore = screenTextResult.Category1Score;
                uploadAssetResult.Category2TextScore = screenTextResult.Category2Score;
                uploadAssetResult.Category3TextScore = screenTextResult.Category3Score;
                uploadAssetResult.Category1TextTag   = screenTextResult.Category1Tag;
                uploadAssetResult.Category2TextTag   = screenTextResult.Category2Tag;
                uploadAssetResult.Category3TextTag   = screenTextResult.Category3Tag;
            }
            var reviewVideoRequestJson = CreateReviewRequestObject(uploadAssetResult, frameEntityList);

            if (string.IsNullOrWhiteSpace(reviewVideoRequestJson))
            {
                throw new Exception("Video review process failed in CreateVideoReviewInContentModerator");
            }
            var reviewIds = await ExecuteCreateReviewApi(reviewVideoRequestJson);

            reviewId        = reviewIds.FirstOrDefault();
            frameEntityList = framegenerator.GenerateFrameImages(frameEntityList, uploadAssetResult, reviewId);
            await CreateAndPublishReviewInContentModerator(uploadAssetResult, frameEntityList, reviewId, path, screenTextResult);

            return(reviewId);
        }
Exemple #2
0
        public async Task <string> CreateAndPublishReviewInContentModerator(UploadAssetResult assetinfo, List <ProcessedFrameDetails> frameEntityList, string reviewId, string path, TranscriptScreenTextResult screenTextResult)
        {
            bool isSuccess    = false;
            bool isTranscript = false;

            isSuccess = await SubmitAddFramesReview(frameEntityList, reviewId, assetinfo);

            if (!isSuccess)
            {
                Console.WriteLine("Add Frame API call failed.");
                throw new Exception();
            }

            if (File.Exists(path))
            {
                if (ValidateVtt(path))
                {
                    isTranscript = await SubmitTranscript(reviewId, path);
                }
                if (isTranscript)
                {
                    isSuccess = await UploadScreenTextResult(reviewId, JsonConvert.SerializeObject(screenTextResult?.TranscriptProfanity));

                    if (!isSuccess)
                    {
                        Console.WriteLine("ScreenTextResult API call failed.");
                        throw new Exception();
                    }
                }
                else
                {
                    Console.WriteLine("Upload vtt failed.");
                    throw new Exception();
                }
                try
                {
                    File.Delete(path);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            isSuccess = PublishReview(reviewId);
            if (!isSuccess)
            {
                throw new Exception("Publish review failed.");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("\nReview Created Successfully and the review Id {0}", reviewId);
            }
            CleanUp(reviewId);
            return(reviewId);
        }
Exemple #3
0
        /// <summary>
        /// Identifying profanity words
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        private async Task <TranscriptScreenTextResult> TextScreen(string filepath, List <ProcessedFrameDetails> frameEntityList)
        {
            List <TranscriptProfanity> profanityList = new List <TranscriptProfanity>();
            bool          category1Tag             = false;
            bool          category2Tag             = false;
            bool          category3Tag             = false;
            double        category1Score           = 0;
            double        category2Score           = 0;
            double        category3Score           = 0;
            List <string> vttLines                 = File.ReadAllLines(filepath).Where(line => !line.Contains("NOTE Confidence:") && line.Length > 0).ToList();
            StringBuilder sb                       = new StringBuilder();
            List <CaptionScreentextResult> csrList = new List <CaptionScreentextResult>();
            CaptionScreentextResult        captionScreentextResult = new CaptionScreentextResult()
            {
                Captions = new List <string>()
            };

            foreach (var line in vttLines.Skip(1))
            {
                if (line.Contains("-->"))
                {
                    if (sb.Length > 0)
                    {
                        captionScreentextResult.Captions.Add(sb.ToString());
                        sb.Clear();
                    }
                    if (captionScreentextResult.Captions.Count > 0)
                    {
                        csrList.Add(captionScreentextResult);
                        captionScreentextResult = new CaptionScreentextResult()
                        {
                            Captions = new List <string>()
                        };
                    }
                    string[] times           = line.Split(new string[] { "-->" }, StringSplitOptions.RemoveEmptyEntries);
                    string   startTimeString = times[0].Trim();
                    string   endTimeString   = times[1].Trim();
                    int      startTime       = (int)TimeSpan.ParseExact(startTimeString, @"hh\:mm\:ss\.fff", CultureInfo.InvariantCulture).TotalMilliseconds;
                    int      endTime         = (int)TimeSpan.ParseExact(endTimeString, @"hh\:mm\:ss\.fff", CultureInfo.InvariantCulture).TotalMilliseconds;
                    captionScreentextResult.StartTime = startTime;
                    captionScreentextResult.EndTime   = endTime;
                }
                else
                {
                    sb.Append(line);
                }
                if (sb.Length + line.Length > 1024)
                {
                    captionScreentextResult.Captions.Add(sb.ToString());
                    sb.Clear();
                }
            }
            if (sb.Length > 0)
            {
                captionScreentextResult.Captions.Add(sb.ToString());
            }
            if (captionScreentextResult.Captions.Count > 0)
            {
                csrList.Add(captionScreentextResult);
            }
            int waitTime = 1000;

            foreach (var csr in csrList)
            {
                bool   captionAdultTextTag     = false;
                bool   captionRacyTextTag      = false;
                bool   captionOffensiveTextTag = false;
                Screen screenRes = new Screen();
                bool   retry     = true;

                foreach (var caption in csr.Captions)
                {
                    while (retry)
                    {
                        try
                        {
                            System.Threading.Thread.Sleep(waitTime);
                            var lang = await CMClient.TextModeration.DetectLanguageAsync("text/plain", caption);

                            var res = await CMClient.TextModeration.ScreenTextWithHttpMessagesAsync(lang.DetectedLanguageProperty, "text/plain", caption, null, null, null, true);

                            screenRes = res.Body;
                            retry     = false;
                        }
                        catch (Exception e)
                        {
                            if (e.Message.Contains("429"))
                            {
                                Console.WriteLine($"Moderation API call failed. Message: {e.Message}");
                                waitTime = (int)(waitTime * 1.5);
                                Console.WriteLine($"wait time: {waitTime}");
                            }
                            else
                            {
                                retry = false;
                                Console.WriteLine($"Moderation API call failed. Message: {e.Message}");
                            }
                        }
                    }

                    if (screenRes != null)
                    {
                        TranscriptProfanity transcriptProfanity = new TranscriptProfanity();
                        transcriptProfanity.TimeStamp = "";
                        List <Terms> transcriptTerm = new List <Terms>();
                        if (screenRes.Terms != null)
                        {
                            foreach (var term in screenRes.Terms)
                            {
                                var profanityobject = new Terms
                                {
                                    Term  = term.Term,
                                    Index = term.Index.Value
                                };
                                transcriptTerm.Add(profanityobject);
                            }
                            transcriptProfanity.Terms = transcriptTerm;
                            profanityList.Add(transcriptProfanity);
                        }
                        if (screenRes.Classification.Category1.Score.Value > _amsConfig.Category1TextThreshold)
                        {
                            captionAdultTextTag = true;
                        }
                        if (screenRes.Classification.Category2.Score.Value > _amsConfig.Category2TextThreshold)
                        {
                            captionRacyTextTag = true;
                        }
                        if (screenRes.Classification.Category3.Score.Value > _amsConfig.Category3TextThreshold)
                        {
                            captionOffensiveTextTag = true;
                        }
                        if (screenRes.Classification.Category1.Score.Value > _amsConfig.Category1TextThreshold)
                        {
                            category1Tag = true;
                        }
                        if (screenRes.Classification.Category2.Score.Value > _amsConfig.Category2TextThreshold)
                        {
                            category2Tag = true;
                        }
                        if (screenRes.Classification.Category3.Score.Value > _amsConfig.Category3TextThreshold)
                        {
                            category3Tag = true;
                        }
                        category1Score = screenRes.Classification.Category1.Score.Value > category1Score ? screenRes.Classification.Category1.Score.Value : category1Score;
                        category2Score = screenRes.Classification.Category2.Score.Value > category2Score ? screenRes.Classification.Category2.Score.Value : category2Score;
                        category3Score = screenRes.Classification.Category3.Score.Value > category3Score ? screenRes.Classification.Category3.Score.Value : category3Score;
                    }
                    foreach (var frame in frameEntityList.Where(x => x.TimeStamp >= csr.StartTime && x.TimeStamp <= csr.EndTime))
                    {
                        frame.IsAdultTextContent     = captionAdultTextTag;
                        frame.IsRacyTextContent      = captionRacyTextTag;
                        frame.IsOffensiveTextContent = captionOffensiveTextTag;
                    }
                }
            }
            TranscriptScreenTextResult screenTextResult = new TranscriptScreenTextResult()
            {
                TranscriptProfanity = profanityList,
                Category1Tag        = category1Tag,
                Category2Tag        = category2Tag,
                Category3Tag        = category3Tag,
                Category1Score      = category1Score,
                Category2Score      = category2Score,
                Category3Score      = category3Score
            };

            return(screenTextResult);
        }