Thursday, September 1, 2011

How to parse Flickr Image Urls

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: else's list/ else's list/

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;


Post a Comment