示例#1
0
        private static async Task StoreBreakdownJsonInCosmos(VideoBreakdown videoBreakdownJson, TraceWriter log)
        {
            //string CosmosCollectionName = ConfigurationManager.AppSettings["CosmosCollectionName"];
            //if (String.IsNullOrEmpty(CosmosCollectionName))
            //    throw new ApplicationException("CosmosCollectionName app setting not set");
            var cosmosHelper   = new CosmosHelper(log);
            var collectionName = "Breakdowns";
            var client         = cosmosHelper.GetCosmosClient(collectionName);
            var json           = JsonConvert.SerializeObject(videoBreakdownJson);

            cosmosHelper.LogMessage($"saving json: {json}");
            // save the json as a new document
            try
            {
                Document r =
                    await client.UpsertDocumentAsync(
                        UriFactory.CreateDocumentCollectionUri(CosmosHelper.CosmosDatabasename, collectionName),
                        videoBreakdownJson);
            }
            catch (Exception e)
            {
                cosmosHelper.LogMessage($"error inserting document in cosmos: {e.Message}");
                // ignore for now, but maybe should replace the document if it already exists..
                // seems to be caused by dev environment where queue items are being reprocesssed
            }
        }
示例#2
0
        private static async Task StoreFacesAsync(Face f, VideoBreakdown poco, VideoIndexerHelper videoIndexerHelper)
        {
            var faceStream = await DownloadWebResource(f.thumbnailFullUrl);

            var blob = await UploadFileToBlobStorage(faceStream, $"{poco.id}/faces/{f.shortId}.jpg", "image/jpg", videoIndexerHelper);

            f.thumbnailFullUrl = blob.Uri.ToString();
        }
示例#3
0
        /// <summary>
        ///     Store the images referenced in the breakdown and update their location in the JSON prior to
        ///     storing in the database.
        /// </summary>
        /// <param name="poco"></param>
        /// <param name="videoIndexerHelper"></param>
        /// <returns></returns>
        private static async Task ExtractImages(VideoBreakdown poco, TraceWriter log, VideoIndexerHelper videoIndexerHelper)
        {
            var baseHelper = new BaseHelper(log);

            baseHelper.LogMessage($"start task extract images");
            // download thumbnail and store in blob storage

            var memSreamOfResource = await DownloadWebResource(poco.summarizedInsights.thumbnailUrl);

            var newBlob = await UploadFileToBlobStorage(memSreamOfResource, $"{poco.id}/video-thumbnail.jpg",
                                                        "image/jpg", videoIndexerHelper);

            string newImageUrl = newBlob.Uri.AbsoluteUri;

            // replace urls in breakdown
            poco.summarizedInsights.thumbnailUrl = newImageUrl;
            poco.breakdowns[0].thumbnailUrl      = newImageUrl;
            baseHelper.LogMessage($"wait for task extract images to finish");
            await Task.WhenAll(poco.summarizedInsights.faces.Select(f => StoreFacesAsync(f, poco, videoIndexerHelper)));
        }
示例#4
0
        private static async Task GetCaptionsVttAsync(string id, VideoBreakdown videoBreakdownPoco, string language, VideoIndexerHelper videoIndexerHelper)
        {
            var client      = videoIndexerHelper.GetVideoIndexerHttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request parameters
            queryString["language"] = language;
            var uri = $"https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns/{id}/VttUrl?" +
                      queryString;

            // this returns a url to the captions file
            var response = await client.GetAsync(uri);

            var vttUrl =
                response.Content.ReadAsStringAsync().Result
                .Replace("\"", "");     // seems like the url is always wrapped in quotes

            // download actual vtt file and store in blob storage
            var vttStream = await DownloadWebResource(vttUrl);

            await UploadFileToBlobStorage(vttStream, $"{videoBreakdownPoco.id}/{language}.vtt", "text/plain", videoIndexerHelper);

            //TODO: put reference to vtt in breakdown?
        }