Image() public method

public Image ( String Query, String Options, String Market, String Adult, Double Latitude, Double Longitude, String ImageFilters ) : DataServiceQuery
Query String Bing search query Sample Values : xbox
Options String Specifies options for this request for all Sources. Valid values are: DisableLocationDetection, EnableHighlighting. Sample Values : EnableHighlighting
Market String Market. Note: Not all Sources support all markets. Sample Values : en-US
Adult String Adult setting is used for filtering sexually explicit content Sample Values : Moderate
Latitude Double Latitude Sample Values : 47.603450
Longitude Double Longitude Sample Values : -122.329696
ImageFilters String Array of strings that filter the response the API sends based on size, aspect, color, style, face or any combination thereof. Valid values are: Size:Small, Size:Medium, Size:Large, Size:Width:[Width], Size:Height:[Height], Aspect:Square, Aspect:Wide, Aspect:Tall, Color:Color, Color:Monochrome, Style:Photo, Style:Graphics, Face:Face, Face:Portrait, Face:Other. Sample Values : Size:Small+Aspect:Square
return DataServiceQuery
        public IEnumerable<Bing.ImageResult> GetImages(string year, string make, string model, string trim)
        {
            string query = "";

            //if (trim == null)
            query = year + " " + make + " " + model;
            //else
            //    query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.
            string rootUri = "https://api.datamarket.azure.com/Bing/Search";
            var bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.
            var accountKey = "bFrWiOhaXScS2yyTcXpzk2s5+Gc78yRDhp/qjHKYU+8";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);

            // Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);
            imageQuery = imageQuery.AddQueryOption("$top", 4);
            var imageResults = imageQuery.Execute();

            // if response code != 200, skip the image


            // extract the properties needed for the images
            
            return imageResults;
        }
        public IEnumerable <Bing.ImageResult> GetImages(string year, string make, string model, string trim)
        {
            string query = "";

            //if (trim == null)
            query = year + " " + make + " " + model;
            //else
            //    query = year + " " + make + " " + model + " " + trim;

            // Create a Bing container.
            string rootUri       = "https://api.datamarket.azure.com/Bing/Search";
            var    bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));

            // Replace this value with your account key.
            var accountKey = "bFrWiOhaXScS2yyTcXpzk2s5+Gc78yRDhp/qjHKYU+8";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);

            // Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);

            imageQuery = imageQuery.AddQueryOption("$top", 4);
            var imageResults = imageQuery.Execute();

            // if response code != 200, skip the image


            // extract the properties needed for the images

            return(imageResults);
        }
Beispiel #3
0
        private async void Search_Click(object sender, RoutedEventArgs e) {
            string accountKey = "<ApiKey goes here>";

            var context = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Data.ashx/Bing/Search"));
            context.Credentials = new NetworkCredential(accountKey, accountKey);

            var result = await context.Image(this.SearchQuery.Text, "en-US", null, null, null, null).ExecuteAsync();
            ImagesList.ItemsSource = result.ToList();
        }
        public async Task ExecuteSearch(string searchQuery)
        {
            _lastSearch = searchQuery;
            var context = new BingSearchContainer(
                new Uri("https://api.datamarket.azure.com/Data.ashx/Bing/Search"));
            context.Credentials = new NetworkCredential(BingAzureDataMarket.AccountKey, BingAzureDataMarket.AccountKey);

            var serviceQuery = context.Image(searchQuery, "en-US", null, null, null, null);
            var result = await serviceQuery.ExecuteAsync();

            ImagesList.ItemsSource = result.ToList();
        }
        public void FindImageUrlsFor(string searchQuery)
        {
            // Create a Bing container.
            string rootUri       = "https://api.datamarket.azure.com/Bing/Search";
            var    bingContainer = new Bing.BingSearchContainer(new Uri(rootUri));
            // Replace this value with your account key.
            var accountKey = "YourAccountKey";

            // Configure bingContainer to use your credentials.
            bingContainer.Credentials = new NetworkCredential(accountKey, accountKey);
            // Build the query.
            var imageQuery = bingContainer.Image(query, null, null, null, null, null, null);

            imageQuery.BeginExecute(_onImageQueryComplete, imageQuery);
        }
Beispiel #6
0
        private static async void Bot_MessagedReceived(object sender, MessageEventArgs e)
        {
            if (e.Message.IsAuthor) return;

            //help cmd
            string[] cmds = {"!help", "!ping", "!yt <search term>", "!img <search term>", "!8ball <question>", "!roll", "!bass" };
            if (e.Message.Text.ToLower().Equals(prefix + "help"))
            {
                string cmdStringer = e.User.Mention + "\n__**Commands:**__";
                foreach (string s in cmds)
                {
                    cmdStringer += "\n\t- " + s;
                }
                await e.Channel.SendMessage(cmdStringer);
            }
            //ping cmd
            else if (e.Message.Text.ToLower().Equals(prefix + "ping"))
            {
                await e.Channel.SendMessage(e.User.Mention + " Pong");
            }
            //yt cmd
            else if (e.Message.Text.ToLower().Contains(prefix + "yt") && e.Message.Text.IndexOf(prefix) == 0)
            {
                ytSearch = e.Message.Text.Remove(0, 3);
                if (String.IsNullOrWhiteSpace(ytSearch))
                {
                    await e.Channel.SendMessage(e.User.Mention + " Your command must have a search term attached to it! Use \"!help\" for assistance.");
                }
                else
                {
                    new Program().YoutubeMethod().Wait();
                    await e.Channel.SendMessage(e.User.Mention + " " + ytResult);
                }
            }
            //image cmd
            else if (e.Message.Text.ToLower().Contains(prefix + "img") && e.Message.Text.IndexOf(prefix) == 0)
            {
                string searchTerm = e.Message.Text.Remove(0, 5);
                if (String.IsNullOrWhiteSpace(searchTerm))
                {
                    await e.Channel.SendMessage(e.User.Mention + " Your command must have a search term attached to it! Use \"!help\" for assistance.");
                }
                else
                {

                    var bing = new BingSearchContainer(
                        new Uri("https://api.datamarket.azure.com/Bing/Search/"))
                    { Credentials = new NetworkCredential(bingSearchKey, bingSearchKey) };

                    var query = bing.Image(searchTerm, "EnableHighlighting", "en-US", "Moderate", null, null, null);
                    var results = query.Execute();

                    ImageResult[] aResults = results.ToArray<ImageResult>();

                    int index = r.Next(0, aResults.Length);
                    ImageResult item = aResults[index];

                    await e.Channel.SendMessage(e.User.Mention + " " + item.MediaUrl);
                }
            }
            //8ball cmd
            else if (e.Message.Text.ToLower().Contains(prefix + "8ball") && e.Message.Text.IndexOf(prefix) == 0)
            {
                string question = e.Message.Text.Remove(0, 6);
                if (string.IsNullOrWhiteSpace(question))
                {
                    await e.Channel.SendMessage(e.User.Mention + " Your command must have a question attached to it! Use \"!help\" for assistance.");
                    return;
                }

                string[] responses = {"Not likely.", "More than likely"};
                int index = r.Next(0, responses.Length);
                await e.Channel.SendMessage(e.User.Mention + " " + responses[index]);
            }
            //roll cmd
            else if (e.Message.Text.ToLower().Equals(prefix + "roll"))
            {
                int face = r.Next(1, 7);
                await e.Channel.SendMessage(e.User.Mention + " Rolled a " + face);
                switch (face)
                {
                    case 1:
                        await e.Channel.SendFile("Assets/Dice/dice1.png");
                        break;
                    case 2:
                        await e.Channel.SendFile("Assets/Dice/dice2.png");
                        break;
                    case 3:
                        await e.Channel.SendFile("Assets/Dice/dice3.png");
                        break;
                    case 4:
                        await e.Channel.SendFile("Assets/Dice/dice4.png");
                        break;
                    case 5:
                        await e.Channel.SendFile("Assets/Dice/dice5.png");
                        break;
                    case 6:
                        await e.Channel.SendFile("Assets/Dice/dice6.png");
                        break;
                    default:
                        await e.Channel.SendFile("Assets/Dice/dice1.png");
                        break;
                }
            }
            //bass cmd
            else if (e.Message.Text.ToLower().Equals(prefix + "bass"))
            {
                if (e.User.VoiceChannel != null)
                {
                    //set up
                    bot.UsingAudio(x =>
                    {
                        x.Mode = AudioMode.Outgoing;
                    });

                    //joining a channel
                    var voiceChannel = bot.FindServers("Bot Testing Place").FirstOrDefault().VoiceChannels.FirstOrDefault();
                    _vClient = await bot.GetService<AudioService>().Join(voiceChannel);

                    SendAudio("Assets/Audio/bass.mp3");


                }
                else
                {
                    await e.Channel.SendMessage(e.User.Mention + " You must be in a voice room to do this. Use \"!help\" for assistance.");
                }
            }

        }
        static void GetTotori(string searchWord, int _page, bool isSafeSearch, SearchEngine engine = SearchEngine.Google)
        {
            var page = _page * 20;
            var urlWord = Uri.EscapeUriString(searchWord);
            int done = 0, fail = 0;
            List<string> totori = new List<string>();
            Console.WriteLine("Page "+_page+" GET Start\nSearch Engine: "+engine.ToString());

            if (engine == SearchEngine.Google)
            {
                #region Google画像検索
                WebClient wc = new WebClient();
                wc.Proxy = null;
                //%E3%83%88%E3%83%88%E3%83%AA
                var isSafeStr = "off";
                if (isSafeSearch)
                    isSafeStr = "on";
                byte[] data = wc.DownloadData("https://www.google.co.jp/search?q=" + urlWord + "&hl=ja&safe=" + isSafeStr + "&sout=1&biw=1920&tbm=isch&sa=N&start=" + page);
                //Console.WriteLine("解析中");
                Encoding enc = Encoding.GetEncoding("Shift_JIS");
                string html = enc.GetString(data);
                var links = html.Split(new string[] { "http://www.google.co.jp/imgres?imgurl=", "&amp;imgrefurl=" }, StringSplitOptions.RemoveEmptyEntries);
                //string[] tototi = new string[30];

                foreach (var item in links)
                {
                    if (item.StartsWith("http") && (item.EndsWith("jpg") || item.EndsWith("png") || item.EndsWith("bmp") || item.EndsWith("gif")))
                    {
                        totori.Add(item);
                        //Console.WriteLine(item);
                    }
                }
                #endregion
            }
            else if (engine == SearchEngine.Bing)
            {
                #region Bing画像検索
                var bing = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/")) {
                        Credentials = new NetworkCredential(bingKey, bingKey)
                };

                var isSafeStr = "Off";
                if (isSafeSearch)
                    isSafeStr = "Moderate";

                var query = bing.Image(searchWord, null, null, isSafeStr, null, null, null, 20, page);
                var results = query.Execute();

                foreach (var result in results)
                {
                    totori.Add(result.MediaUrl);
                }
                #endregion
            }

            Parallel.ForEach(totori, (u) =>
            {
                try
                {
                    var url = new Uri(u);

                    var filePath = Path.Combine(savePath, Path.GetFileName(url.LocalPath));
                    new WebClient().DownloadFile(url, filePath);
                    done++;
                    //Console.WriteLine("downloaded: {0} => {1}", url, filePath);
                }
                catch// (Exception e)
                {
                    fail++;
                    //Console.WriteLine("failed: {0}, {1}", url, e);
                }
            });
            //Console.WriteLine("end");
            Console.WriteLine("Page " + _page + " End");
            Console.WriteLine("Done: " + done + " Error: " + fail);
        }
Beispiel #8
0
 /// <summary>
 /// Next: 
 /// download images to file
 /// name according to bird type 
 /// delete bad images in explorer
 /// crop
 /// resize
 /// flip
 /// 
 /// 
 /// </summary>
 /// <param name="args"></param>
 static void Main(string[] args)
 {
     var searches = new NameValueCollection
     {
         {"bluetit", "bluetit"},
         {"coaltit", "coaltit"},
         {"greattit", "greattit"},
         {"longtailedtit", "longtailed tit"},
         {"greenfinch", "greenfinch"},
         {"goldfinch", "european goldfinch"},
         {"chaffinch", "chaffinch"},
         {"blackbirdm", "turdus merula male"},
         {"blackbirdf", "turdus merula female"},
         {"thrush", "song thrush"},
         {"robin", "european robin"},
         {"dunnock", "dunnock"},
         {"nuthatch", "eurasian nuthatch"},
         {"greaterspottedwoodpecker", "greater spotted woodpecker"},
         {"greenwoodpecker", "green woodpecker"},
         {"woodpigeon", "columba palumbus"},
         {"collareddove", "collared dove"},
         {"wren", "eurasian wren"},
         {"magpie", "eurasian magpie"},
         {"starling", "european starling"},
     };
     const string apiKey = "px10eK/V0YPxELtEk4t8CIesrDR90AkoauBbx+lh/s4";
     var searchContainer = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search"))
     {
         Credentials = new NetworkCredential(apiKey, apiKey)
     };
     var webClient = new WebClient();
     while (true)
     {
         Console.WriteLine("Enter search term:");
         var searchTerm = Console.ReadLine();
         if (string.IsNullOrEmpty(searchTerm))
             break;
         Console.WriteLine("Enter file prefix:");
         var filePrefix = Console.ReadLine();
         if (string.IsNullOrEmpty(filePrefix))
             filePrefix = searchTerm;
         var query = searchContainer.Image(searchTerm, null, "en-GB", null, null, null, null);
         query.AddQueryOption("$top", 20);
         Console.WriteLine("Starting search");
         var results = query.Execute();
         if (results == null)
         {
             Console.WriteLine("results == null");
             Console.ReadKey();
             break;
         }
         Console.WriteLine("Top 20 results:");
         if (Directory.Exists(filePrefix))
         {
             Directory.Move(filePrefix, string.Format("{0}-{1}", filePrefix, DateTime.Now.ToString("yyyyMMddTHHmmssfff")));
         }
         Directory.CreateDirectory(filePrefix);
         var i = 1;
         foreach (var result in results.Take(20))
         {
             Console.WriteLine("{0} - {1} [{2}x{3}]", result.Title, result.MediaUrl, result.Height, result.Width);
             var ext = Path.GetExtension(result.MediaUrl);
             try
             {
                 webClient.DownloadFile(result.MediaUrl, Path.Combine(filePrefix, string.Format("{0}-{1}{2}", filePrefix, i++, ext)));
             }
             catch (Exception ex)
             {
                 Console.WriteLine("Exception downloading: " + ex.Message);
             }
         }
         Console.WriteLine();
     }
 }
        private async Task<DataFeed> EnrichWithImagesAsync(DataFeed feed)
        {
            const string key = "ZvD71NLFp4EFiActP24HNCNHey1r4m64bwMQPTh8AZg";

            if (!string.IsNullOrEmpty(feed.Image))
            {
                return feed;
            }
                
            if (feed.Concepts == null)
            {
                return null;
            }

            var bingContainer = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/v1/"))
            {
                Credentials = new NetworkCredential(key, key)
            };

            var imagesQuery = bingContainer.Image(string.Join(" ", feed.Concepts), null, null, "Moderate", null, null, "Size:Large");
            IEnumerable<ImageResult> imagesResults = await 
                Task<IEnumerable<ImageResult>>.Factory.FromAsync(imagesQuery.BeginExecute, imagesQuery.EndExecute, null);

            ImageResult image = imagesResults.FirstOrDefault();
            if (image != null)
            {
                feed.Image = image.MediaUrl;
                return feed;
            }

            return null;
        }