public FlickrPhoto GetOnePhotoInfoFromFlickr(string photoId) { Flickr flickr = new Flickr(_apiKey, _secret); flickr.InstanceCacheDisabled = true; PhotoInfo photoInfo = new PhotoInfo(); FlickrPhoto flickrPhoto = new FlickrPhoto(); try { photoInfo = flickr.PhotosGetInfo(photoId); flickrPhoto.PictureId = photoInfo.PhotoId; flickrPhoto.OwnerName = !string.IsNullOrWhiteSpace(photoInfo.OwnerRealName) ? photoInfo.OwnerRealName : photoInfo.OwnerUserName; flickrPhoto.Title = photoInfo.Title; flickrPhoto.Description = photoInfo.Description; flickrPhoto.AvailablePublic = photoInfo.IsPublic; flickrPhoto.SmallImageUrl = photoInfo.Small320Url; } catch (Exception ex) { if (ex is PhotoNotFoundException) { flickrPhoto.AvailablePublic = false; } } return flickrPhoto; }
private FlickrNet.PhotoInfo SafelyGetInfo(string photoid) { FlickrNet.PhotoInfo pInfo = null; for (int i = 0; i < MAXTRIES; i++) { try { pInfo = flickrObj.PhotosGetInfo(photoid); return(pInfo); } catch (FlickrNet.FlickrApiException e) { if (e.Code == 1) { return(null); // Photo not found. } // Maximum attempts over. if (i == MAXTRIES - 1) { PrintException(e); if (e.Code == CODE_TIMEOUT) { _isConnected = false; throw e; } } continue; } } throw new Exception("FlickrCommunicator: GetInfo(photoid) unreachable code"); }
public void PhotoInfoParseFull() { string x = "<photo id=\"7519320006\">" + "<location latitude=\"54.971831\" longitude=\"-1.612683\" accuracy=\"16\" context=\"0\" place_id=\"Ke8IzXlQV79yxA\" woeid=\"15532\">" + "<neighbourhood place_id=\"Ke8IzXlQV79yxA\" woeid=\"15532\">Central</neighbourhood>" + "<locality place_id=\"DW0IUrFTUrO0FQ\" woeid=\"20928\">Gateshead</locality>" + "<county place_id=\"myqh27pQULzLWcg7Kg\" woeid=\"12602156\">Tyne and Wear</county>" + "<region place_id=\"2eIY2QFTVr_DwWZNLg\" woeid=\"24554868\">England</region>" + "<country place_id=\"cnffEpdTUb5v258BBA\" woeid=\"23424975\">United Kingdom</country>" + "</location>" + "</photo>"; System.IO.StringReader sr = new System.IO.StringReader(x); System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(sr); xr.Read(); var info = new PhotoInfo(); ((IFlickrParsable)info).Load(xr); Assert.AreEqual("7519320006", info.PhotoId); Assert.IsNotNull(info.Location); Assert.AreEqual((GeoAccuracy)16, info.Location.Accuracy); Assert.IsNotNull(info.Location.Country); Assert.AreEqual("cnffEpdTUb5v258BBA", info.Location.Country.PlaceId); }
internal static string UrlFormat(PhotoInfo p, string size, string format) { if (size == "_o") { return(UrlFormat(photoUrl, p.Farm, p.Server, p.PhotoId, p.OriginalSecret, size, format)); } else { return(UrlFormat(photoUrl, p.Farm, p.Server, p.PhotoId, p.Secret, size, format)); } }
internal static string UrlFormat(PhotoInfo p, string size, string extension) { if (size == "_o" || size == "original") { return(UrlFormat(p.Farm, p.Server, p.PhotoId, p.OriginalSecret, size, extension)); } else { return(UrlFormat(p.Farm, p.Server, p.PhotoId, p.Secret, size, extension)); } }
/// <summary> /// Get the tag list for a given photo. /// </summary> /// <param name="photoId">The id of the photo to return tags for.</param> /// <returns>An instance of the <see cref="PhotoInfo"/> class containing only the <see cref="PhotoInfo.Tags"/> property.</returns> public Collection <PhotoInfoTag> TagsGetListPhoto(string photoId) { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("method", "flickr.tags.getListPhoto"); parameters.Add("api_key", apiKey); parameters.Add("photo_id", photoId); PhotoInfo info = GetResponseCache <PhotoInfo>(parameters); return(info.Tags); }
public void LoadPicture(FlickrNet.PhotoInfo photoInfo) { this.DataContext = photoInfo; _isShowingComments = false; _isShowingNotes = false; _isShowingViews = false; if (photoInfo.Title == string.Empty || photoInfo.Title.Length == 0) { grdTitle.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } else { grdTitle.Visibility = Visibility.Visible; } String resultDescription = Regex.Replace(photoInfo.Description, @"<[^>]*>", String.Empty); tbDescription.Text = resultDescription; string resultDisplayName = "by "; if (photoInfo.OwnerRealName != string.Empty) { resultDisplayName += photoInfo.OwnerRealName; } if (photoInfo.OwnerUserName != string.Empty) { resultDisplayName += " (" + photoInfo.OwnerUserName + ")"; } tbOwnerDisplayName.Text = resultDisplayName; tbLicense.Text = "License : " + photoInfo.License; butViews.Content = "Views : " + photoInfo.ViewCount; butComments.Content = "Comments : " + photoInfo.CommentsCount; if (photoInfo.Notes != null) { butNotes.Content = "Notes : " + photoInfo.Notes.Count; } if (ChangeViewState != null) { ChangeViewState("Normal", null); } //try to load photostream }
public void PhotoInfoLocationParseShortTest() { string x = "<photo id=\"7519320006\">" + "<location latitude=\"-23.32\" longitude=\"-34.2\" accuracy=\"10\" context=\"1\" />" + "</photo>"; System.IO.StringReader sr = new System.IO.StringReader(x); System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(sr); xr.Read(); var info = new PhotoInfo(); ((IFlickrParsable)info).Load(xr); Assert.AreEqual("7519320006", info.PhotoId); Assert.IsNotNull(info.Location); Assert.AreEqual((GeoAccuracy)10, info.Location.Accuracy); }
public override void CreateContentFromUrl(string url, ref string title, ref string newContent) { Match m = Regex.Match(url, PHOTO_REGEX_URL); if (!m.Success) { base.CreateContentFromUrl(url, ref title, ref newContent); } else { string photoId = m.Groups["id"].Value; // get photo FlickrNet.Flickr flickrProxy = FlickrPluginHelper.GetFlickrProxy(); FlickrNet.PhotoInfo photo = flickrProxy.PhotosGetInfo(photoId); title = photo.Title; newContent = string.Format("<p><a href=\"{0}\" title=\"{2}\"><img alt=\"{2}\" border=\"0\" src=\"{1}\"></a></p>", photo.WebUrl, photo.MediumUrl, HtmlServices.HtmlEncode(photo.Title)); } }
/// <summary> /// Returns the location data for a give photo. /// </summary> /// <param name="photoId">The ID of the photo to return the location information for.</param> /// <returns>Returns null if the photo has no location information, otherwise returns the location information.</returns> public PlaceInfo PhotosGeoGetLocation(string photoId) { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("method", "flickr.photos.geo.getLocation"); parameters.Add("photo_id", photoId); try { PhotoInfo info = GetResponseCache <PhotoInfo>(parameters); return(info.Location); } catch (FlickrApiException ex) { if (ex.Code == 2) { return(null); } throw; } }
private void AddPhotoToList(FlickrNet.Flickr f, FlickrNet.Photo flickrPhoto, Photoset photoset) { // Filter by date, if filter option enabled and date taken is known. if (!Settings.FilterByDate || flickrPhoto.DateTakenUnknown || (flickrPhoto.DateTaken.Date >= Settings.StartDate && flickrPhoto.DateTaken.Date <= Settings.StopDate)) { Photo photo = new Photo(flickrPhoto, photoset); PhotoList.Add(photo); // Get the photo info to get the raw tags, and put them into the photo object. // The raw tags are as uploaded or entered -- with spaces, punctuation, and // upper/lower case. FlickrNet.PhotoInfo info = f.PhotosGetInfo(flickrPhoto.PhotoId); photo.Tags.Clear(); for (int i = 0; i < info.Tags.Count; i++) { photo.Tags.Add(info.Tags[i].Raw); } } }
public Favourite ConvertPhotoToFavourite(FlickrNet.Photo photo, PhotoInfo photoInfo, string userAvatarUri) { return new Favourite() { MediaLicense = getLicenseTypeName(photo.License), AggregateId = Guid.NewGuid().ToString(), MediaDescription = photo.Description == null ? string.Empty : photo.Description, MediaTitle = photo.Title == null ? string.Empty : photo.Title, MediaUrlSmall = photo.SmallUrl == null ? string.Empty : photo.SmallUrl, MediaUrlMedium = photo.MediumUrl == null ? string.Empty : photo.MediumUrl, MediaUserAvatar = photoInfo.OwnerBuddyIcon, MediaUserName = photoInfo.OwnerUserName, UserAvatar = userAvatarUri, UserName = FlickrPerson.UserName, UserRealName = FlickrPerson.RealName, TimeStamp = DateTime.Now.ToUniversalTime(), EntityId = photo.PhotoId }; }
internal static string UrlFormat(PhotoInfo p, string size, string format) { if( size == "_o" ) return UrlFormat(photoUrl, p.Farm, p.Server, p.PhotoId, p.OriginalSecret, size, format); else return UrlFormat(photoUrl, p.Farm, p.Server, p.PhotoId, p.Secret, size, format); }
public async void UnfavouritePhoto(Photo photo, PhotoInfo photoInfo, string userAvatarUri) { //if (ChangeState != null) ChangeState("PhotoFavourited", new CustomEventArgs() { Photo = photo }); //return; DownloadService.Current.DownloadCount++; _flickr.FavoritesRemoveAsync(photo.PhotoId, async (nr) => { DownloadService.Current.DownloadCount--; //UPDATE UI THAT FAVOURITE HAS BEEN REMOVED if (!nr.HasError) { await _dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.DispatchedHandler(() => { if (ChangeState != null) ChangeState("PhotoUnfavourited", new CustomEventArgs() { Photo = photo }); }) ); } else { await _dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.DispatchedHandler(() => { _raiseError(nr.ErrorMessage); }) ); } }); }
// To keep it simple, if any of the steps involved in retrieving // a photo fails, we'll assume that the entire sequence has failed, // and it should be retried from step 1. // This method only retrieves the photo from flickr, but doesn't store // it automatically in database. public Photo RetrievePhoto(string photoid) { if (!_isConnected) { return(null); } // Step 1: Retrieve photo information. FlickrNet.PhotoInfo pInfo = SafelyGetInfo(photoid); if (pInfo == null) { UpdateUIAboutConnection(); return(null); } Photo photo = new Photo(photoid, pInfo.Title, pInfo.Description, pInfo.License, pInfo.Visibility.IsPublic, pInfo.Visibility.IsFriend, pInfo.Visibility.IsFamily, pInfo.Dates.raw_lastupdate.ToString()); photo.DatePosted = pInfo.Dates.raw_posted.ToString(); // Step 2: Retrieve Square Thumbnail. Gdk.Pixbuf thumbnail = PersistentInformation.GetInstance().GetThumbnail(photoid); if (thumbnail == null) { // This determines what size is download for the image. Gdk.Pixbuf buf = SafelyDownloadPhoto(pInfo.SquareThumbnailUrl); if (buf == null) { UpdateUIAboutConnection(); return(null); } photo.Thumbnail = buf; } // Step 3: Retrieve Small image. Gdk.Pixbuf smallimage = PersistentInformation.GetInstance().GetSmallImage(photoid); if (smallimage == null) { Gdk.Pixbuf buf = SafelyDownloadPhoto(pInfo.SmallUrl); if (buf == null) { UpdateUIAboutConnection(); return(null); } photo.SmallImage = buf; } // Step 4: Retrieve tags. If no tags, then just return the photo. if (pInfo.Tags.TagCollection == null) { return(photo); } // Otherwise, populate the tags, and then return the photo. ArrayList tags = new ArrayList(); foreach (FlickrNet.PhotoInfoTag tag in pInfo.Tags.TagCollection) { tags.Add(tag.TagText); } photo.Tags = tags; // Step 5: Retrieve comments. if (pInfo.CommentsCount > 0) { ArrayList comments = SafelyGetComments(photoid); if (comments != null) { Dictionary <string, Comment> localcommentsdic = new Dictionary <string, Comment>(); foreach (Comment comment in PersistentInformation.GetInstance().GetCommentsForPhoto(photoid)) { localcommentsdic.Add(comment.CommentId, comment); } foreach (Comment comment in comments) { if (localcommentsdic.ContainsKey(comment.CommentId)) { // Comment is present in db. But check if the comment html text // is still the same, or has been changed online. if (!comment.CommentHtml.Equals(localcommentsdic[comment.CommentId])) { PersistentInformation.GetInstance().UpdateComment(photoid, comment.CommentId, comment.CommentHtml, false); } } else // comment is not present locally. { PersistentInformation.GetInstance().InsertComment(photoid, comment.CommentId, comment.CommentHtml, comment.UserName); } localcommentsdic.Remove(comment.CommentId); } // The comments left in localcommentsdic are the ones which have // been deleted from the server. foreach (string commentid in localcommentsdic.Keys) { PersistentInformation.GetInstance().DeleteComment(photoid, commentid); } } } else // There're no comments online. So, wipe out any if present in db. { PersistentInformation.GetInstance().DeleteCleanComments(photoid); } return(photo); }
public async void FavouritePhoto(Photo photo, PhotoInfo photoInfo, string userAvatarUri) { //if (ChangeState != null) ChangeState("PhotoFavourited", new CustomEventArgs() { Photo = photo }); //return; DownloadService.Current.DownloadCount++; _flickr.FavoritesAddAsync(photo.PhotoId, async (nr) => { DownloadService.Current.DownloadCount--; if (FlickrPerson != null) { //ADD TO PUBLIC AZURE FAVOURTES AzureMobileService.Current.SaveFavouriteToCloud(ConvertPhotoToFavourite(photo, photoInfo, userAvatarUri)); } //UPDATE UI THAT FAVOURITE HAS BEEN ADDED if (!nr.HasError) { await _dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.DispatchedHandler(() => { if (ChangeState != null) ChangeState("PhotoFavourited", new CustomEventArgs() { Photo = photo }); }) ); } else { await _dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.DispatchedHandler(() => { _raiseError(nr.ErrorMessage); }) ); } }); }
public async void PromotePhoto(Photo photo, PhotoInfo photoInfo, string userAvatarUri) { DownloadService.Current.DownloadCount++; //ADD TO PUBLIC AZURE PROMOTIONS AzureMobileService.Current.SavePromoteToCloud(new Promote() { MediaLicense = getLicenseTypeName(photo.License), AggregateId = Guid.NewGuid().ToString(), MediaDescription = photo.Description == null ? string.Empty : photo.Description, MediaTitle = photo.Title == null ? string.Empty : photo.Title, MediaUrlSmall = photo.SmallUrl == null ? string.Empty : photo.SmallUrl, MediaUrlMedium = photo.MediumUrl == null ? string.Empty : photo.MediumUrl, MediaUserAvatar = photoInfo.OwnerBuddyIcon, MediaUserName = photoInfo.OwnerUserName, UserAvatar = userAvatarUri, UserName = FlickrPerson.UserName, UserRealName = FlickrPerson.RealName, TimeStamp = DateTime.Now.ToUniversalTime(), EntityId = photo.PhotoId }); //UPDATE UI THAT FAVOURITE HAS BEEN ADDED await _dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.DispatchedHandler(() => { DownloadService.Current.DownloadCount--; if (ChangeState != null) ChangeState("PhotoPromoted", new CustomEventArgs() { Photo = photo }); }) ); }
internal static string UrlFormat(PhotoInfo p, string size, string extension) { if (size == "_o" || size == "original") return UrlFormat(p.Farm, p.Server, p.PhotoId, p.OriginalSecret, size, extension); else return UrlFormat(p.Farm, p.Server, p.PhotoId, p.Secret, size, extension); }
public Photo CreatePhoto(PhotoInfo photoInfo) { return new Photo { FlickrId = photoInfo.PhotoId, MediumUrl = photoInfo.MediumUrl, SquareThumbnail = photoInfo.SquareThumbnailUrl, ThumbNailUrl = photoInfo.ThumbnailUrl, LargeUrl = photoInfo.LargeUrl, SmallUrl = photoInfo.SmallUrl }; }