public async Task <IActionResult> SearchVideos(string keyword)
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            var accountAccesstoken = await helper.GetAccountAccessTokenString(false);

            string requestUrl = $"https://api.videoindexer.ai/" +
                                $"{this.AzureConfiguration.VideoIndexerConfiguration.Location}" +
                                $"/Accounts/{this.AzureConfiguration.VideoIndexerConfiguration.AccountId}" +
                                $"/Videos/Search?" +
                                //$"[?sourceLanguage]" +
                                //$"[&isBase]" +
                                //$"[&hasSourceVideoFile]" +
                                //$"[&sourceVideoId]" +
                                //$"[&state]" +
                                //$"[&privacy]" +
                                //$"[&id]" +
                                //$"[&partition]" +
                                //$"[&externalId]" +
                                //$"[&owner]" +
                                //$"[&face]" +
                                //$"[&animatedcharacter]" +
                                $"query={keyword}" +
                                //$"[&textScope]" +
                                //$"[&language]" +
                                //$"[&createdAfter]" +
                                //$"[&createdBefore]" +
                                //$"[&pageSize]" +
                                //$"[&skip]" +
                                $"&accessToken={accountAccesstoken}";
            HttpClient client = new HttpClient();
            var        result = await client.GetFromJsonAsync <SearchVideosResponse>(requestUrl);

            return(Ok(result));
        }
        public async Task <IActionResult> GetPersons(string personModelId)
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            GetPersonsResponse result = await helper.GetAllPersonsInPersonModel(personModelId);

            return(Ok(result));
        }
        public async Task <IActionResult> GetVideoAccessToken(string videoId, bool allowEdit = false)
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            var videoAccesstoken = await helper.GetVideoAccessTokenStringAsync(videoId, allowEdit);

            return(Ok(videoAccesstoken));
        }
        public async Task <IActionResult> GetAccountAccessToken(bool allowEdit = false)
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            string result = await helper.GetAccountAccessTokenString(allowEdit);

            return(Ok(result));
        }
        public async Task <IActionResult> ListVideos()
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            ListVideosResponse result = await helper.GetAllVideos();

            return(Ok(result));
        }
        public async Task <IActionResult> GetPersonPicture(string personModelId,
                                                           string personId, string faceId)
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            string base64String = await helper.GetPersonPictureInBase64(personModelId, personId, faceId);

            return(Ok(base64String));
        }
        public async Task <IActionResult> GetPersonsModels()
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());

            PersonModel[] result = await helper.GetAllPersonsModels();

            return(Ok(result));
        }
        public async Task <IActionResult> GetAllPersons()
        {
            GetAllPersonsModel model = null;

            this.MemoryCache.TryGetValue <GetAllPersonsModel>(Constants.ALLPERSONS_INFO, out model);
            if (model == null)
            {
                AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                             this.CreateAuthorizedHttpClient());
                model = await helper.GetAllPersonsData();
            }
            return(Ok(model));
        }
        public async Task <IActionResult> GetAllKeywords()
        {
            List <KeywordInfoModel> lstKeywords = null;

            this.MemoryCache.TryGetValue <List <KeywordInfoModel> >
                (Constants.ALLVIDEOS_KEYWORDS, out lstKeywords);
            if (lstKeywords == null)
            {
                AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                             this.CreateAuthorizedHttpClient());
                lstKeywords = await helper.GetAllKeywords();
            }
            return(Ok(lstKeywords.OrderByDescending(p => p.Appeareances).ToList()));
        }
Exemple #10
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                await Task.Yield();

                AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                             this.HttpClientFactory.CreateClient());
                var taskGetAllPersonsData    = helper.GetAllPersonsData();
                var taskGetAllKeywordsAction = helper.GetAllKeywords();
                Task.WaitAll(new Task[] { taskGetAllPersonsData, taskGetAllKeywordsAction });
                this.MemoryCache.Set <GetAllPersonsModel>(Constants.ALLPERSONS_INFO, taskGetAllPersonsData.Result);
                this.MemoryCache.Set <List <KeywordInfoModel> >(Constants.ALLVIDEOS_KEYWORDS, taskGetAllKeywordsAction.Result);
                await Task.Delay(TimeSpan.FromMinutes(5));
            }
        }
        private async Task <HttpResponseMessage> AnalyzeVideo(UploadVideoModel model)
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            string accountAccesstoken = await helper.GetAccountAccessTokenString(true);

            string requestUrl = $"https://api.videoindexer.ai/" +
                                $"{this.AzureConfiguration.VideoIndexerConfiguration.Location}" +
                                $"/Accounts/{this.AzureConfiguration.VideoIndexerConfiguration.AccountId}" +
                                $"/Videos" +
                                $"?name={EncodeUrl(model.Name)}" +
                                //$"[&privacy]" +
                                //$"[&priority]" +
                                //$"[&description]" +
                                //$"[&partition]" +
                                //$"[&externalId]" +
                                //$"[&externalUrl]" +
                                //$"[&metadata]" +
                                //$"[&language]" +
                                $"&videoUrl={EncodeUrl(model.VideoUrl)}" +
                                //$"[&fileName]" +
                                //$"[&indexingPreset]" +
                                //$"[&streamingPreset]" +
                                //$"[&linguisticModelId]" +
                                //$"[&personModelId]" +
                                //$"[&animationModelId]" +
                                $"&sendSuccessEmail={model.SendSuccessEmail}" +
                                //$"[&assetId]" +
                                //$"[&brandsCategories]" +
                                $"&accessToken={accountAccesstoken}";

            if (!string.IsNullOrWhiteSpace(model.CallbackUrl))
            {
                requestUrl +=
                    $"&callbackUrl={EncodeUrl(model.CallbackUrl)}";
            }
            var client = this.CreateAuthorizedHttpClient();
            var result = await client.PostAsync(requestUrl, null);

            return(result);
        }
        public async Task <IActionResult> GetVideoThumbnail(string videoId, string thumbnailId)
        {
            AzureVideoIndexerHelper helper = new AzureVideoIndexerHelper(this.AzureConfiguration,
                                                                         this.CreateAuthorizedHttpClient());
            string videoAccessToken = await helper.GetVideoAccessTokenStringAsync(videoId, true);

            string format     = "Base64";
            string requestUrl = $"{this.AzureConfiguration.VideoIndexerConfiguration.BaseAPIUrl}" +
                                $"/{this.AzureConfiguration.VideoIndexerConfiguration.Location}" +
                                $"/Accounts/{this.AzureConfiguration.VideoIndexerConfiguration.AccountId}" +
                                $"/Videos/{videoId}" +
                                $"/Thumbnails/{thumbnailId}" +
                                $"?format={format}" +
                                $"&accessToken={videoAccessToken}";
            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key",
                                             this.AzureConfiguration.VideoIndexerConfiguration.SubscriptionKey);
            var result = await client.GetStringAsync(requestUrl);

            return(Ok(result));
        }