/// <summary> /// Returns the URL for a particular picture. /// Typically you call GetPhotosInSet first and then this method to get /// the complete URL for a picture in the set in a particular size. /// </summary> /// <param name="photo">Details of the photo</param> /// <param name="size">The size requested for the picture</param> /// <returns>URL as a string</returns> public static string GetPhotoUrl(FlickrInfo photo, PhotoSizeEnum size) { string baseUrl = string.Format("http://farm{0}.static.flickr.com", photo.Farm); string url = string.Format("{0}/{1}/{2}_{3}{4}.jpg", baseUrl, photo.Server, photo.Id, photo.Secret, size.Description()); return(url); }
public ListItem(int publicationId, FlickrInfo info) { Info = info; if (info.IsPhoto) { // format of photo item id: [flickr photo id]_[flickr photo secret]_[flickr photo set id] string itemId = string.Format("{0}_{1}_{2}", info.Id, info.Secret, info.PhotoSetId); _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, itemId, DisplayTypeId, EclItemTypes.File); } else { _id = Provider.HostServices.CreateEclUri(publicationId, Provider.MountPointId, info.Id, DisplayTypeId, EclItemTypes.Folder); } }
/// <summary> /// Returns the photo info. /// </summary> /// <param name="id">Id of the photo</param> /// <param name="secret">Secret of the photo</param> /// <param name="photoSetId">The ID of the photoset this photo belongs to</param> /// <returns></returns> public FlickrInfo GetPhotoInfo(string id, string secret, string photoSetId) { const string getInfoMethod = "flickr.photos.getInfo"; string url = string.Format("{0}?method={1}&api_key={2}&photo_id={3}&secret={4}", ApiUrl, getInfoMethod, ApiKey, id, secret); XElement responseXml = SubmitRequest(url); XElement photoElement = responseXml.Element("photo"); if (photoElement != null) { FlickrInfo photo = new FlickrInfo(photoElement, photoSetId); photo.Url = GetPhotoUrl(photo, PhotoSizeEnum.Large); return(photo); } return(null); }
/// <summary> /// Fills the details about a picture. At this time the only value that /// it fills is the description. Typically you call GetPhotosInSet first /// and then this method to populate the description of an individual /// picture. /// </summary> /// <param name="photo">A FlickrInfo with information about the picture to fill. /// </param> public void FillPhotoDetails(ref FlickrInfo photo) { const string getInfoMethod = "flickr.photos.getInfo"; string url = string.Format("{0}?method={1}&api_key={2}&photo_id={3}&secret={4}", ApiUrl, getInfoMethod, ApiKey, photo.Id, photo.Secret); XElement responseXml = SubmitRequest(url); XElement photoElement = responseXml.Element("photo"); if (photoElement != null) { XElement descriptionElement = photoElement.Element("description"); if (descriptionElement != null) { photo.Description = descriptionElement.Value; } } }
/// <summary> /// Returns the URL for a particular picture with a given width. /// The returned URL will be based on the specified width, if available the /// exact width will be returned, else the nearest smaller variant will be used. /// </summary> /// <param name="photo">Details of the photo</param> /// <param name="width">The width in pixels for the picture, defaults to <see cref="MaxWidth"/></param> /// <returns>URL as a string</returns> public static string GetPhotoUrl(FlickrInfo photo, int width = MaxWidth) { if (width >= MaxWidth) { // width 1024, height 768 return(GetPhotoUrl(photo, PhotoSizeEnum.Large)); } if (width >= 800) { // width 800, height 600 return(GetPhotoUrl(photo, PhotoSizeEnum.Svga)); } if (width >= 640) { // width 640, height 480 return(GetPhotoUrl(photo, PhotoSizeEnum.Vga)); } if (width >= 500) { // width 500, height 375 return(GetPhotoUrl(photo, PhotoSizeEnum.Medium)); } if (width >= 320) { // width 320, height 240 return(GetPhotoUrl(photo, PhotoSizeEnum.Qvga)); } if (width >= 240) { // width 240, height 180 return(GetPhotoUrl(photo, PhotoSizeEnum.Small)); } if (width >= 150) { // width 150, height 150 return(GetPhotoUrl(photo, PhotoSizeEnum.LargeSquare)); } if (width >= 100) { // width 100, height 75 return(GetPhotoUrl(photo, PhotoSizeEnum.Thumbnail)); } // width 75, height 75 return(GetPhotoUrl(photo, PhotoSizeEnum.Square)); }
/// <summary> /// Returns the photo info. /// </summary> /// <param name="id">Id of the photo</param> /// <param name="secret">Secret of the photo</param> /// <param name="photoSetId">The ID of the photoset this photo belongs to</param> /// <returns></returns> public FlickrInfo GetPhotoInfo(string id, string secret, string photoSetId) { const string getInfoMethod = "flickr.photos.getInfo"; string url = string.Format("{0}?method={1}&api_key={2}&photo_id={3}&secret={4}", ApiUrl, getInfoMethod, ApiKey, id, secret); XElement responseXml = SubmitRequest(url); XElement photoElement = responseXml.Element("photo"); if (photoElement != null) { FlickrInfo photo = new FlickrInfo(photoElement, photoSetId); photo.Url = GetPhotoUrl(photo, PhotoSizeEnum.Large); return photo; } return null; }
/// <summary> /// Returns the URL for a particular picture with a given width. /// The returned URL will be based on the specified width, if available the /// exact width will be returned, else the nearest smaller variant will be used. /// </summary> /// <param name="photo">Details of the photo</param> /// <param name="width">The width in pixels for the picture, defaults to <see cref="MaxWidth"/></param> /// <returns>URL as a string</returns> public static string GetPhotoUrl(FlickrInfo photo, int width = MaxWidth) { if (width >= MaxWidth) { // width 1024, height 768 return GetPhotoUrl(photo, PhotoSizeEnum.Large); } if (width >= 800) { // width 800, height 600 return GetPhotoUrl(photo, PhotoSizeEnum.Svga); } if (width >= 640) { // width 640, height 480 return GetPhotoUrl(photo, PhotoSizeEnum.Vga); } if (width >= 500) { // width 500, height 375 return GetPhotoUrl(photo, PhotoSizeEnum.Medium); } if (width >= 320) { // width 320, height 240 return GetPhotoUrl(photo, PhotoSizeEnum.Qvga); } if (width >= 240) { // width 240, height 180 return GetPhotoUrl(photo, PhotoSizeEnum.Small); } if (width >= 150) { // width 150, height 150 return GetPhotoUrl(photo, PhotoSizeEnum.LargeSquare); } if (width >= 100) { // width 100, height 75 return GetPhotoUrl(photo, PhotoSizeEnum.Thumbnail); } // width 75, height 75 return GetPhotoUrl(photo, PhotoSizeEnum.Square); }
/// <summary> /// Returns the URL for a particular picture. /// Typically you call GetPhotosInSet first and then this method to get /// the complete URL for a picture in the set in a particular size. /// </summary> /// <param name="photo">Details of the photo</param> /// <param name="size">The size requested for the picture</param> /// <returns>URL as a string</returns> public static string GetPhotoUrl(FlickrInfo photo, PhotoSizeEnum size) { string baseUrl = string.Format("http://farm{0}.static.flickr.com", photo.Farm); string url = string.Format("{0}/{1}/{2}_{3}{4}.jpg", baseUrl, photo.Server, photo.Id, photo.Secret, size.Description()); return url; }
public FlickrPhoto(int publicationId, FlickrInfo info) : base(publicationId, info) { // if info needs to be fully loaded, do so here }