public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); var subscriptionKey = "YOUR_SUBSCRIPTION_KEY"; var location = "northeurope"; // Change region if needed var accountId = "YOUR_ACCOUNT_ID"; // Gets all the videos in the account List <string> videoList = await GetVideoList(subscriptionKey, location, accountId); List <VideoIndex> videoIndexes = new List <VideoIndex>(); foreach (string videoId in videoList) { VideoIndex videoIndex = await GetVideoIndex(videoId, subscriptionKey, location, accountId); videoIndexes.Add(videoIndex); } Console.WriteLine("\n\n"); // Get only important info List <VideoInfo> videosInfo = new List <VideoInfo>(); foreach (VideoIndex videoIndex in videoIndexes) { Console.WriteLine("Video info:\n"); VideoInfo videoInfo = new VideoInfo(); videoInfo.id = videoIndex.id; Console.WriteLine("ID: " + videoInfo.id); videoInfo.name = videoIndex.name; Console.WriteLine("Name: " + videoInfo.name); Console.WriteLine("Keywords:"); foreach (KeywordObject keyword in videoIndex.summarizedInsights.keywords) { videoInfo.keywords.Add(keyword.name); Console.WriteLine(keyword.name); } Console.WriteLine("\nKnown faces:"); foreach (FaceObject face in videoIndex.summarizedInsights.faces) { if (!face.name.Contains("Unknown")) { videoInfo.knownFaces.Add(face.name); Console.WriteLine(face.name); } } videosInfo.Add(videoInfo); Console.WriteLine("\n\n"); } return(videosInfo != null ? (ActionResult) new OkObjectResult(videosInfo) : new BadRequestObjectResult("Please pass a name on the query string or in the request body")); }
// Gets the index of a video static async Task <VideoIndex> GetVideoIndex(string videoId, string subscriptionKey, string location, string accountId) { VideoIndex videoIndex = new VideoIndex(); var client = new HttpClient(); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey); // Getting video access token var queryString = HttpUtility.ParseQueryString(string.Empty); queryString["allowEdit"] = "false"; var uri = "https://api.videoindexer.ai/auth/" + location + "/Accounts/" + accountId + "/Videos/" + videoId + "/AccessToken?" + queryString; var response = await client.GetAsync(uri); var contents = await response.Content.ReadAsStringAsync(); Console.WriteLine("Video Access Token: \n" + contents); // Getting video index var accessToken = HttpUtility.ParseQueryString(string.Empty); contents = contents.Replace("\"", ""); accessToken["accessToken"] = contents; var uri2 = "https://api.videoindexer.ai/" + location + "/Accounts/" + accountId + "/Videos/" + videoId + "/Index?" + accessToken; var responseIndex = await client.GetAsync(uri2); if (responseIndex.IsSuccessStatusCode) { var contentsIndex = await responseIndex.Content.ReadAsStringAsync(); // Parsing index into object videoIndex = JsonConvert.DeserializeObject <VideoIndex>(contentsIndex); return(videoIndex); } else { throw new Exception((int)responseIndex.StatusCode + "-" + responseIndex.StatusCode.ToString()); } }