Example #1
0
        List <Models.FlickrPhoto> GetPhotosFromFlickr(int pageindex = 0)
        {
            List <Models.FlickrPhoto> retVal = null;

            FlickrNet.Flickr flickr = new FlickrNet.Flickr(Manager.Settings.Current.FlickrAPIKey);
            flickr.InstanceCacheDisabled = true;

            FlickrNet.FoundUser userInfo = flickr.PeopleFindByUserName(Manager.Settings.Current.FlickrUserName);
            string flickrUserId          = userInfo.UserId;

            ViewBag.FlickrFullName = userInfo.FullName;

            FlickrNet.Person user = flickr.PeopleGetInfo(flickrUserId);
            ViewBag.FlickrFullName = user.RealName;

            FlickrNet.PhotoSearchOptions option = new FlickrNet.PhotoSearchOptions();
            option.UserId = flickrUserId;
            option.Page   = pageindex;

            FlickrNet.PhotoCollection photosets = flickr.PhotosSearch(option);
            if (photosets != null && photosets.Count > 0)
            {
                DataTable photos = UnigateObject.Query(Manager.Settings.Current.PhotoListTableName)
                                   .Column("Slug")
                                   .SortDesc("CreateDate")
                                   .ToDataTable();

                List <string> slugs = new List <string>();
                if (photos != null && photos.Rows.Count > 0)
                {
                    slugs = photos.AsEnumerable().Select(p => p.Field <string>("Slug")).ToList();
                }

                retVal = photosets.Where(p => !slugs.Any(s => s == p.PhotoId)).Select(p => new Models.FlickrPhoto()
                {
                    DownloadUrl = !string.IsNullOrEmpty(p.LargeUrl) ? p.LargeUrl : (!string.IsNullOrEmpty(p.MediumUrl) ? p.MediumUrl : p.SmallUrl),
                    ViewUrl     = p.SmallUrl,
                    Title       = p.Title,
                    PhotoId     = p.PhotoId
                }).ToList <Models.FlickrPhoto>();
            }

            return(retVal);
        }
Example #2
0
        public Photo[] GetPhotos(string apiKey, string tags)
        {
            FlickrNet.Flickr.CacheDisabled = true;
            FlickrNet.Flickr flickr = new FlickrNet.Flickr(apiKey);

            FlickrNet.PhotoSearchOptions options = new FlickrNet.PhotoSearchOptions();
            options.Tags    = tags;
            options.Extras  = FlickrNet.PhotoSearchExtras.DateTaken | FlickrNet.PhotoSearchExtras.Geo | FlickrNet.PhotoSearchExtras.OwnerName;
            options.PerPage = 1000;
            options.Text    = tags;
            options.TagMode = FlickrNet.TagMode.AllTags;

            List <Photo> photos = new List <Photo>();

            foreach (FlickrNet.Photo photo in flickr.PhotosSearch(options).PhotoCollection)
            {
                try { photos.Add(new Photo(photo, "{0}")); }
                catch { }
            }

            return(photos.ToArray());
        }
Example #3
0
        public Photo[] GetPhotos( string apiKey, string tags )
        {
            FlickrNet.Flickr.CacheDisabled = true;
            FlickrNet.Flickr flickr = new FlickrNet.Flickr( apiKey );

            FlickrNet.PhotoSearchOptions options = new FlickrNet.PhotoSearchOptions();
            options.Tags = tags;
            options.Extras = FlickrNet.PhotoSearchExtras.DateTaken | FlickrNet.PhotoSearchExtras.Geo | FlickrNet.PhotoSearchExtras.OwnerName;
			options.PerPage = 1000;
			options.Text = tags;
			options.TagMode = FlickrNet.TagMode.AllTags;

            List<Photo> photos = new List<Photo>();

            foreach ( FlickrNet.Photo photo in flickr.PhotosSearch( options ).PhotoCollection )
            {
				try { photos.Add( new Photo( photo, "{0}" ) ); }
				catch { }
            }

            return photos.ToArray();
        }
Example #4
0
        static void Main(string[] args)
        {
            var key = ConfigurationManager.AppSettings["APIKey"];
            var secret = ConfigurationManager.AppSettings["APISecret"];
            FlickrNet.Flickr f = new FlickrNet.Flickr(key, secret);

            if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["accesstoken"]))
            {
                var requesttoken = f.OAuthGetRequestToken("oob");
                var url = f.OAuthCalculateAuthorizationUrl(requesttoken.Token, FlickrNet.AuthLevel.Write);
                Process.Start(url);
                Console.Write("Please enter the 9 digit code Flickr gave you");
                var code = Console.ReadLine();
                var settings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var accesstoken = f.OAuthGetAccessToken(requesttoken.Token, requesttoken.TokenSecret, code);
                //settings.
                settings.AppSettings.Settings.Add("accesstoken", accesstoken.Token);
                settings.AppSettings.Settings.Add("accesstokensecret", accesstoken.TokenSecret);
                settings.Save();
            }

            else
            {
                f.OAuthAccessToken = ConfigurationManager.AppSettings["accesstoken"];
                f.OAuthAccessTokenSecret = ConfigurationManager.AppSettings["accesstokensecret"];
                var searchoptions = new FlickrNet.PhotoSearchOptions() { UserId = "me", MinUploadDate = DateTime.Parse("2013-10-01"), Extras=FlickrNet.PhotoSearchExtras.Tags,Page=2 };

                var collection = f.PhotosSearch(searchoptions);

                var filteredcollection = collection.Where(photo => photo.Title.StartsWith("DSC") && !HasFileNameTag(photo));
                foreach (FlickrNet.Photo photo in filteredcollection)
                {
                    f.PhotosAddTags(photo.PhotoId, "filename:" + photo.Title);
                }

            }
        }
Example #5
0
        private void GetImageUrlsForSentence(string query)
        {
            if (rdoFlickr.Checked)
            {
                FlickrNet.Flickr flickr = new FlickrNet.Flickr("580162ba802ed95a92fc92494dcdecbf", "a6b6d63a6ce977c5");
                FlickrNet.PhotoSearchOptions options = new FlickrNet.PhotoSearchOptions();
                options.Tags = query;
                options.PerPage = 10;
                //options.IsCommons = true;
                options.Licenses.Add(FlickrNet.LicenseType.NoKnownCopyrightRestrictions);
                options.Licenses.Add(FlickrNet.LicenseType.AttributionCC);
                options.Licenses.Add(FlickrNet.LicenseType.AttributionNoDerivativesCC);
                options.Licenses.Add(FlickrNet.LicenseType.AttributionShareAlikeCC);

                var result = flickr.PhotosSearch(options);
                SearchCompleted(result);

                flickr.PhotosSearchAsync(options, asyncResult =>
                    {
                        if (asyncResult.HasError)
                        {
                            TextBox txtError = new TextBox();
                            txtError.Multiline = true;
                            txtError.Dock = DockStyle.Fill;
                            txtError.Text = asyncResult.Error.ToString();
                            flowLayoutPanel1.Controls.Add(txtError);

                            return;
                        }

                        var photos = asyncResult.Result;

                        SearchCompleted(photos);
                    });
            }

            else if (rdoBing.Checked)
            {
                using (BingPortTypeClient client = new BingPortTypeClient())
                {
                    client.SearchCompleted += new EventHandler<SearchCompletedEventArgs>(client_SearchCompleted);
                    var searchRequest = new SearchRequest();
                    searchRequest.Adult = BingSearchService.AdultOption.Strict;
                    searchRequest.AdultSpecified = true;
                    searchRequest.Market = "en-US";
                    searchRequest.Version = "2.2";
                    searchRequest.AppId = "C208A7E582F635C7768950E74C8FDC274A0EA7B4";
                    searchRequest.Sources = new BingSearchService.SourceType[] { SourceType.Image };
                    searchRequest.Query = query;

                    searchRequest.Image = new ImageRequest();
                    searchRequest.Image.Count = 10;
                    progressBar1.Step = (int)100 / (int)searchRequest.Image.Count;
                    searchRequest.Image.CountSpecified = true;

                    searchRequest.Image.Offset = 0;
                    searchRequest.Image.OffsetSpecified = true;

                    client.SearchAsync(searchRequest);
                }
            }
        }
Example #6
0
        public void GetNewWallpaper()
        {
            NotifyIconText = "Retrieving next picture...";
            NotifyIconIcon = WallpaperFlickr.Properties.Resources.flickrwait;
            IsNotifyFail   = false;

            if (ApiKey.Equals(string.Empty))
            {
                NotifyIconText = "API key missing";
                NotifyIconIcon = WallpaperFlickr.Properties.Resources.flickrbad;
                IsNotifyFail   = true;
                return;
            }

            FlickrNet.Flickr flickr = new FlickrNet.Flickr();
            flickr.ApiKey = ApiKey;

            FlickrNet.PhotoCollection photos = null;

            switch (_settings.SearchOrFaves)
            {
            case 0:
                FlickrNet.PhotoSearchOptions options = new FlickrNet.PhotoSearchOptions();
                if (!Tags.Trim().Equals(string.Empty))
                {
                    options.Tags    = Tags;
                    options.TagMode = GetTagMode();
                }
                if (!UserId.Trim().Equals(string.Empty))
                {
                    FlickrNet.FoundUser fuser;
                    string   UserName     = "";
                    string[] AllUserNames = UserId.Split(',');
                    UserName = AllUserNames[new Random().Next(0, AllUserNames.GetUpperBound(0) + 1)];
                    try
                    {     // Exception handler added by CLR 2010-06-11
                        fuser = flickr.PeopleFindByUserName(UserName.Trim());
                    }
                    catch (Exception ex)
                    {
                        FailWithError(ex);
                        return;
                    }
                    if (!fuser.UserId.Equals(string.Empty))
                    {
                        options.UserId = fuser.UserId;
                    }
                }
                options.PrivacyFilter = FlickrNet.PrivacyFilter.PublicPhotos;
                options.SortOrder     = GetSortOrder();
                options.PerPage       = 365;

                try
                {
                    photos = flickr.PhotosSearch(options);
                    //photos = flickr.PhotosGetRecent(); // this was me trying to do Explore stuff, but failed
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message);
                    FailWithError(ex);
                    return;
                }
                options = null;
                break;

            case 1:
                try
                {
                    FlickrNet.FoundUser fuser;
                    fuser  = flickr.PeopleFindByUserName(FaveUserId);
                    photos = flickr.FavoritesGetPublicList(fuser.UserId);
                }
                catch (Exception ex)
                {
                    FailWithError(ex);
                    return;
                }
                break;

            case 2:
                // do explore
                try
                {
                    photos = flickr.InterestingnessGetList();
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message);
                    FailWithError(ex);
                    return;
                }
                break;

            default:
                break;
            }


            clsWallpaper wallpaper = new clsWallpaper();

            Random pn = new Random();

            if (photos.Count == 0)
            {
                NotifyIconText = "Specified parameters return no photographs from Flickr";
                NotifyIconIcon = WallpaperFlickr.Properties.Resources.flickrbad;
                IsNotifyFail   = true;
                return;
            }
            else
            {
                int chosePhoto = pn.Next(0, photos.Count);
                //FlickrNet.Sizes fs = flickr.PhotosGetSizes("4570943273");
                FlickrNet.SizeCollection fs;
                bool LoadedWallpaper = false;
                try
                {
                    fs = flickr.PhotosGetSizes(photos[chosePhoto].PhotoId);
                    // Load the last size (which should be "Original"). Doing all this
                    // because photo.OriginalURL just causes an exception
                    LoadedWallpaper = wallpaper.Load(fs[fs.Count - 1].Source, _settings,
                                                     getDisplayStyle(), Application.ExecutablePath, photos[chosePhoto].WebUrl);
                }
                catch (Exception ex) // load failed with an exception
                {
                    FailWithError(ex);
                    return;
                }

                if (!LoadedWallpaper) // load failed, but didn't cause an exception
                {
                    NotifyIconText = "Failed to load wallpaper";
                    NotifyIconIcon = WallpaperFlickr.Properties.Resources.flickrbad;
                    IsNotifyFail   = true;
                    return;
                }

                // Get further info about the photo to display in the tooltip
                FlickrNet.PhotoInfo fi;
                try
                {
                    fi = flickr.PhotosGetInfo(photos[chosePhoto].PhotoId);
                }
                catch (Exception ex)
                {
                    FailWithError(ex);
                    return;
                }

                // Set thumbnail
                NotifyIconIcon = TinyPictureVersion(FileSystem.MyPath() + "\\wallpaper\\_CurrentPaper.bmp");

                FlickrNet.Person fuser;
                string           notifyText = "";
                fuser      = flickr.PeopleGetInfo(photos[chosePhoto].UserId);
                notifyText = fuser.UserName + ": " + photos[chosePhoto].Title;
                string description = fi.Description;
                string location    = "\n";
                if (fi.Location != null)
                {
                    if (fi.Location.County != null)
                    {
                        location += fi.Location.County.Description + ", " + fi.Location.Country.Description;
                    }
                    else
                    {
                        location += fi.Location.Country.Description;
                    }
                }
                description = System.Web.HttpUtility.HtmlDecode(Regex.Replace(description, "<[^>]*>", ""));

                NotifyIconText           = notifyText.Substring(0, Math.Min(63, notifyText.Length));
                NotifyIconBalloonTipText = fi.DateTaken.ToLongDateString() +
                                           location + "\n" + description;
                NotifyIconBalloonTipTitle = photos[chosePhoto].Title;

                if (ShowBubbles)
                {
                    NotifyPropertyChanged("PopupBalloon");
                }
            }

            wallpaper = null;
            flickr    = null;
            photos    = null;
            //notifyIcon1.Icon = WallpaperFlickr.Properties.Resources.flickr;
        }