コード例 #1
0
        public async Task VideoSearch(string subscriptionKey, string query)
        {
            var client = new VideoSearchAPI(new Microsoft.Azure.CognitiveServices.Search.VideoSearch.ApiKeyServiceClientCredentials(subscriptionKey));

            // var client = new ImageSearchClient(new ApiKeyServiceClientCredentials(subscriptionKey));
            try
            {
                var videoResults = client.Videos.SearchAsync(query).Result;
                if (videoResults != null)
                {
                    var activity = MessageFactory.Attachment(new Attachment[]
                    {
                        new Attachment {
                            ContentUrl = videoResults.Value[0].ContentUrl, ContentType = "video/mp4"
                        },
                        new Attachment {
                            ContentUrl = videoResults.Value[1].ContentUrl, ContentType = "video/mp4"
                        },
                        new Attachment {
                            ContentUrl = videoResults.Value[2].ContentUrl, ContentType = "video/mp4"
                        }
                    });
                    await context.SendActivityAsync("Searching for videos related to " + query);

                    await context.SendActivityAsync(activity);
                }
            }
            catch (Exception ex)
            {
                await context.SendActivityAsync("Could not retrieve video results due to:" + ex.Message);
            }
        }
コード例 #2
0
        public async static Task SearchVideoAsync(IDialogContext context, string key, string query)
        {
            IVideoSearchAPI client = new VideoSearchAPI(new Microsoft.Azure.CognitiveServices.Search.VideoSearch.ApiKeyServiceClientCredentials(key));
            var             result = await client.Videos.SearchAsync(query : query, count : 3, length : Microsoft.Azure.CognitiveServices.Search.VideoSearch.Models.VideoLength.Short, freshness : Microsoft.Azure.CognitiveServices.Search.VideoSearch.Models.Freshness.Week);

            if (result?.Value?.Count > 0)
            {
                await context.PostAsync($"Here is top 5 Video search result for **{query}**");

                var message = context.MakeMessage();
                message.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                foreach (var item in result.Value)
                {
                    HeroCard card = new HeroCard
                    {
                        Title  = item.Name,
                        Images = new List <CardImage>
                        {
                            new CardImage(item.ThumbnailUrl)
                        },
                        Buttons = new List <CardAction>
                        {
                            new CardAction(ActionTypes.OpenUrl, "View Video", value: item.ContentUrl)
                        }
                    };
                    message.Attachments.Add(card.ToAttachment());
                }
                await context.PostAsync(message);
            }
        }
コード例 #3
0
        public static void VideoSearchWithFilters(string subscriptionKey)
        {
            var client = new VideoSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey));

            try
            {
                var videoResults = client.Videos.SearchAsync(query: "Interstellar Trailer", pricing: VideoPricing.Free, length: VideoLength.Short, resolution: VideoResolution.HD1080p).Result;
                Console.WriteLine("Search videos for query \"Interstellar Trailer\" that is free, short and 1080p resolution");

                if (videoResults == null)
                {
                    Console.WriteLine("Didn't see any video result data..");
                }
                else
                {
                    if (videoResults.Value.Count > 0)
                    {
                        var firstVideoResult = videoResults.Value.First();

                        Console.WriteLine($"Video result count: {videoResults.Value.Count}");
                        Console.WriteLine($"First video id: {firstVideoResult.VideoId}");
                        Console.WriteLine($"First video name: {firstVideoResult.Name}");
                        Console.WriteLine($"First video url: {firstVideoResult.ContentUrl}");
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find video results!");
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine("Encountered exception. " + ex.Message);
            }
        }
コード例 #4
0
        public static void VideoSearch(string subscriptionKey)
        {
            var client = new VideoSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey));

            try
            {
                var videoResults = client.Videos.SearchAsync(query: "Nasa CubeSat").Result;
                Console.WriteLine("Search videos for query \"Nasa CubeSat\"");

                if (videoResults == null)
                {
                    Console.WriteLine("Didn't see any video result data..");
                }
                else
                {
                    if (videoResults.Value.Count > 0)
                    {
                        var firstVideoResult = videoResults.Value.First();

                        Console.WriteLine($"Video result count: {videoResults.Value.Count}");
                        Console.WriteLine($"First video id: {firstVideoResult.VideoId}");
                        Console.WriteLine($"First video name: {firstVideoResult.Name}");
                        Console.WriteLine($"First video url: {firstVideoResult.ContentUrl}");
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find video results!");
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine("Encountered exception. " + ex.Message);
            }
        }
コード例 #5
0
        public static void VideoTrending(string subscriptionKey)
        {
            var client = new VideoSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey));

            try
            {
                var trendingResults = client.Videos.TrendingAsync().Result;
                Console.WriteLine("Search trending videos");

                if (trendingResults == null)
                {
                    Console.WriteLine("Didn't see any trending video data..");
                }
                else
                {
                    // Banner Tiles
                    if (trendingResults.BannerTiles?.Count > 0)
                    {
                        var firstBannerTile = trendingResults.BannerTiles[0];
                        Console.WriteLine($"Banner tile count: {trendingResults.BannerTiles.Count}");
                        Console.WriteLine($"First banner tile text: {firstBannerTile.Query.Text}");
                        Console.WriteLine($"First banner tile url: {firstBannerTile.Query.WebSearchUrl}");
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find banner tiles!");
                    }

                    // Categories
                    if (trendingResults.Categories?.Count > 0)
                    {
                        var firstCategory = trendingResults.Categories[0];
                        Console.WriteLine($"Category count: {trendingResults.Categories.Count}");
                        Console.WriteLine($"First category title: {firstCategory.Title}");

                        if (firstCategory.Subcategories?.Count > 0)
                        {
                            var firstSubCategory = firstCategory.Subcategories[0];
                            Console.WriteLine($"SubCategory count: {firstCategory.Subcategories.Count}");
                            Console.WriteLine($"First sub category title: {firstSubCategory.Title}");

                            if (firstSubCategory.Tiles?.Count > 0)
                            {
                                var firstTile = firstSubCategory.Tiles[0];
                                Console.WriteLine($"Tile count: {firstSubCategory.Tiles.Count}");
                                Console.WriteLine($"First tile text: {firstTile.Query.Text}");
                                Console.WriteLine($"First tile url: {firstTile.Query.WebSearchUrl}");
                            }
                            else
                            {
                                Console.WriteLine("Couldn't find tiles!");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Couldn't find subcategories!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find categories!");
                    }
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine("Encountered exception. " + ex.Message);
            }
        }
コード例 #6
0
        public static void VideoDetail(string subscriptionKey)
        {
            var client = new VideoSearchAPI(new ApiKeyServiceClientCredentials(subscriptionKey));

            try
            {
                var videoResults = client.Videos.SearchAsync(query: "Interstellar Trailer").Result;

                var firstVideo = videoResults?.Value?.FirstOrDefault();

                if (firstVideo != null)
                {
                    var modules = new List <VideoInsightModule?>()
                    {
                        VideoInsightModule.All
                    };
                    var videoDetail = client.Videos.DetailsAsync(query: "Interstellar Trailer", id: firstVideo.VideoId, modules: modules).Result;
                    Console.WriteLine($"Search detail for video id={firstVideo.VideoId}, name={firstVideo.Name}");

                    if (videoDetail != null)
                    {
                        if (videoDetail.VideoResult != null)
                        {
                            Console.WriteLine($"Expected video id: {videoDetail.VideoResult.VideoId}");
                            Console.WriteLine($"Expected video name: {videoDetail.VideoResult.Name}");
                            Console.WriteLine($"Expected video url: {videoDetail.VideoResult.ContentUrl}");
                        }
                        else
                        {
                            Console.WriteLine("Couldn't find expected video!");
                        }

                        if (videoDetail?.RelatedVideos?.Value?.Count > 0)
                        {
                            var firstRelatedVideo = videoDetail.RelatedVideos.Value[0];
                            Console.WriteLine($"Related video count: {videoDetail.RelatedVideos.Value.Count}");
                            Console.WriteLine($"First related video id: {firstRelatedVideo.VideoId}");
                            Console.WriteLine($"First related video name: {firstRelatedVideo.Name}");
                            Console.WriteLine($"First related video url: {firstRelatedVideo.ContentUrl}");
                        }
                        else
                        {
                            Console.WriteLine("Couldn't find any related video!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find detail about the video!");
                    }
                }
                else
                {
                    Console.WriteLine("Couldn't find video results!");
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine("Encountered exception. " + ex.Message);
            }
        }
コード例 #7
0
        /// <summary>
        /// Método que pesquisa videos do hotel pedido com cognitiveservices do azure
        /// </summary>
        /// <param name="queryHotel"></param>
        /// <param name="canal"></param>
        /// <returns></returns>
        public static List <string> VideoSearch(string queryHotel, string canal)
        {
            var           client     = new VideoSearchAPI(new Microsoft.Azure.CognitiveServices.Search.VideoSearch.ApiKeyServiceClientCredentials(ConfigurationManager.AppSettings["BingSearchKey"].ToString()));
            List <string> urlList    = null;
            int           num_videos = int.Parse(ConfigurationManager.AppSettings["NumVideos"].ToString());

            try
            {
                var imageResults = client.Videos.SearchAsync(query: queryHotel).Result;

                urlList = new List <string>();

                if (imageResults == null)
                {
                    //nao encontrou nada
                    urlList.Add("");
                }
                else
                {
                    // video results
                    if (imageResults.Value.Count > 0)
                    {
                        for (int i = 0; i < num_videos; i++)
                        {
                            urlList.Add(imageResults.Value.ElementAt(i).ContentUrl);
                        }
                    }
                    else
                    {
                        urlList.Add("");
                    }


                    //Console.WriteLine($"Image result total estimated matches: {imageResults.TotalEstimatedMatches}");
                    //Console.WriteLine($"Image result next offset: {imageResults.NextOffset}");

                    //// Pivot suggestions
                    //if (imageResults.PivotSuggestions.Count > 0)
                    //{
                    //    var firstPivot = imageResults.PivotSuggestions.First();

                    //    Console.WriteLine($"Pivot suggestion count: {imageResults.PivotSuggestions.Count}");
                    //    Console.WriteLine($"First pivot: {firstPivot.Pivot}");

                    //    if (firstPivot.Suggestions.Count > 0)
                    //    {
                    //        var firstSuggestion = firstPivot.Suggestions.First();

                    //        Console.WriteLine($"Suggestion count: {firstPivot.Suggestions.Count}");
                    //        Console.WriteLine($"First suggestion text: {firstSuggestion.Text}");
                    //        Console.WriteLine($"First suggestion web search url: {firstSuggestion.WebSearchUrl}");
                    //    }
                    //    else
                    //    {
                    //        Console.WriteLine("Couldn't find suggestions!");
                    //    }
                    //}
                    //else
                    //{
                    //    Console.WriteLine("Couldn't find pivot suggestions!");
                    //}

                    //// Query expansions
                    //if (imageResults.QueryExpansions.Count > 0)
                    //{
                    //    var firstQueryExpansion = imageResults.QueryExpansions.First();

                    //    Console.WriteLine($"Query expansion count: {imageResults.QueryExpansions.Count}");
                    //    Console.WriteLine($"First query expansion text: {firstQueryExpansion.Text}");
                    //    Console.WriteLine($"First query expansion search link: {firstQueryExpansion.SearchLink}");
                    //}
                    //else
                    //{
                    //    Console.WriteLine("Couldn't find query expansions!");
                    //}
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine("Encountered exception. " + ex.Message);
            }

            return(urlList);
        }