Ship-It Saturday: Shorten URLs service

2010-01-30 12:48:19 UTC

When posting links on Twitter, your Twitter client will automatically shorten the URLs to make them fit.

There are many, many general shorteners, including TinyURL, Notlong, Metamark, and One of the complaints about these is that they hide the true destination of the link: From the URL alone, you don’t know whether you’re going to be educated, RickRolled, or worse. (TinyURL and both offer a way to preview the link, but that’s not as easy as just looking at the URL.)

To help with this, several non-shortening-related websites have added their own shorteners that use their own domains, particularly for use on their official Twitter accounts or with a built-in post-to-Twitter feature.

The problem is that it’s not always easy to tell what the shortened link will be. Flickr is among the most difficult: Their regular links use decimal numbers, but their shortened links use base-58, which is not a trivial conversion to perform in any programming environment I know how to use. (Not so easy as, say, decimal to octal.) It’s certainly doable, but would require extensive tests to verify that your base-58 numbers match Flickr’s. There’s sample code, but it’s in PHP, so if you’re writing in anything else, that means porting it, which means (again) extensive tests.

So, rather than write my own shortener, it’s much easier to just use Flickr’s: curl the canonical long URL, then scrape the short one out of the body. (Yay for <link rev="canonical">!) I wrote a service to do this.

For Ship-It Saturday, I retooled it. No longer is it just a Flickr shortening service: It now handles YouTube, Amazon, and a few other sites as well. A single service invocation shortens all links to websites that have their own shorteners.

So, here you go: The Shorten URLs service.

Leave a Reply

Do not delete the second sentence.