Пример #1
0
        public void LoadConfiguration(string config)
        {
            try
            { if (!string.IsNullOrEmpty(config))
              {
                  wiss = WallbaseImageSearchSettings.LoadFromXML(config);
              }
            }
            catch { }

            if (wiss == null)
            {
                wiss = new WallbaseImageSearchSettings();
            }

            txtUserID.Text   = wiss.Username;
            txtPassword.Text = wiss.Password;

            txtSearch.Text = wiss.Query;

            cbArea.SelectedValue = wiss.SA;

            cbWG.Checked = wiss.WG;
            cbW.Checked  = wiss.W;
            cbHR.Checked = wiss.HR;

            cbSFW.Checked     = wiss.SFW;
            cbSketchy.Checked = wiss.SKETCHY;
            cbNSFW.Checked    = wiss.NSFW;

            cbImageSizeType.SelectedValue    = wiss.SO;
            cbOrderBy.SelectedValue          = wiss.OB;
            cbOrderByDirection.SelectedValue = wiss.OBD;

            txtWidth.Text  = wiss.ImageWidth.ToString();
            txtHeight.Text = wiss.ImageHeight.ToString();
            cbAspectRatio.SelectedValue = wiss.AR;

            txtCollectionID.Text = wiss.CollectionID;
            txtFavoritesID.Text  = wiss.FavoriteID;

            cbTopTimespan.SelectedValue = wiss.TopTimespan;

            if (wiss.Color != System.Drawing.Color.Empty)
            {
                pnlColor.BackColor = wiss.Color;
                cdPicker.Color     = wiss.Color;
            }
        }
Пример #2
0
        public PictureList GetPictures(PictureSearch ps)
        {
            WallbaseImageSearchSettings wiss = string.IsNullOrEmpty(ps.SearchProvider.ProviderConfig) ? new WallbaseImageSearchSettings() : WallbaseImageSearchSettings.LoadFromXML(ps.SearchProvider.ProviderConfig);

            //if max picture count is 0, then no maximum, else specified max
            var maxPictureCount = ps.MaxPictureCount > 0?ps.MaxPictureCount : int.MaxValue;
            int pageSize        = wiss.GetPageSize();
            int pageIndex       = ps.PageToRetrieve; //set page to retreive if one is specified
            var imgFoundCount   = 0;

            //authenticate to wallbase
            Authenticate(wiss.Username, wiss.Password);

            var wallResults = new List <Picture>();

            string areaURL = wiss.BuildURL();

            //string postParams = wiss.GetPostParams(search);


            do
            {
                //calculate page index.  Random does not use pages, so for random just refresh with same url
                string strPageNum = (pageIndex > 0 && wiss.SA != "random") || (wiss.SA == "toplist" || wiss.SA == "user/collection" || wiss.SA == "user/favorites") ? (pageIndex * pageSize).ToString() : "";

                string pageURL = areaURL.Contains("{0}") ? string.Format(areaURL, strPageNum) : areaURL;
                //string content = HttpPost(pageURL, postParams);
                string content = string.Empty;

                using (HttpUtility.CookieAwareWebClient _client = new HttpUtility.CookieAwareWebClient(_cookies))
                {
                    try
                    {
                        //if random then don't post values
                        if (wiss.SA == "random")
                        {
                            content = _client.DownloadString(pageURL);
                        }
                        else
                        {
                            byte[] reqResult = _client.UploadValues(pageURL, wiss.GetPostParams());
                            content = System.Text.Encoding.Default.GetString(reqResult);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Logger.Write(string.Format("Failed to download search results from wallbase.cc, error: {0}", ex.ToString()), Log.LoggerLevels.Warnings);
                    }
                }

                if (string.IsNullOrEmpty(content))
                {
                    break;
                }

                //parse html and get count
                var pics = ParsePictures(content);
                imgFoundCount = pics.Count();

                //if we have an image ban list check for them
                // doing this in the provider instead of picture manager
                // ensures that our count does not go down if we have a max
                if (ps.BannedURLs != null && ps.BannedURLs.Count > 0)
                {
                    pics = (from c in pics where !(ps.BannedURLs.Contains(c.Url)) select c).ToList();
                }

                wallResults.AddRange(pics);

                //increment page index so we can get the next set of images if they exist
                pageIndex++;
            } while (imgFoundCount > 0 && wallResults.Count < maxPictureCount && ps.PageToRetrieve == 0);

            PictureList result = FetchPictures(wallResults, ps.PreviewOnly);

            result.Pictures = result.Pictures.Take(maxPictureCount).ToList();

            return(result);
        }