I had to deal with parsing the multiple flickr urls that exist to access an image.
Did you know that there are many different Url's for a single photo?
Here are the one's I've discovered:
flickr.com/photos/userId/id/in/set-setId/
flickr.com/photos/userId/id/in/photostream/
flickr.com/photos/userId/id/someone else's list/
flickr.com/photos/userId/id/datetaken/
flickr.com/photos/userName/id/in/set-setId/
flickr.com/photos/userName/id/in/photostream/
flickr.com/photos/userName/id/someone else's list/
flickr.com/photos/userName/id/datetaken/
flickr.com/photo.gne?id=id
And here is some code to strip all these suckers to get the photo Id:
public string GetFlickrPhotoId(string url)
{
string s = url.ToLower();
// remove everything after /in/ if it exists
s = s.Substring(0, s.IndexOf("/in/") > 0 ? s.IndexOf("/in/") : s.Length);
// remove url, user name, userid, photo.gne?id=id, "/"
s = s.Substring(s.Contains("/") ? s.LastIndexOf("/") : 0, s.Length - (s.Contains("/") ? s.LastIndexOf("/") : 0));
s = s.Replace("photo.gne?id=", string.Empty);
s = s.Replace("/", string.Empty);
return s;
}
No comments:
Post a Comment