GreenStripes: Ruby bindings for libspotify

April 15, 2009

About a week ago, Spotify released libspotify, a C API for writing applications that utilize their service.

Now, while I’m certainly not averse to C, I think that a more human-friendly language is a better fit for many tasks. So I whipped up a set of Ruby bindings that lets you write programs like this one:

session = GreenStripes::Session.new(APPLICATION_KEY, 'GreenStripes', 'tmp', 'tmp')
session.login(USERNAME, PASSWORD)
session.process_events until session.connection_state == GreenStripes::ConnectionState::LOGGED_IN

search = GreenStripes::Search.new(session, 'yakety sax', 0, 100)
session.process_events until search.loaded?
puts "found #{search.num_tracks} tracks"
if search.num_tracks > 0
  track = search.track(0)
  session.process_events until track.loaded? and track.artist(0).loaded?
  puts "the first one is #{track.name} by #{track.artist(0).name}"
end

session.logout
session.process_events until session.connection_state == GreenStripes::ConnectionState::LOGGED_OUT

GreenStripes is very much in a beta stage, lacks features and has bugs, but it’s gotten to a point where you can actually play around with it and build stuff.

Interested? GreenStripes is available in source or gem form from GitHub, where you can also read installation instructions and sign up to be notified of updates:

Getting started with Spotify

March 3, 2009

I’ve introduced a lot of people to Spotify lately, and I tend to say pretty much the same things every time. So, in the interest of having something you can point a web browser at, I decided to sum it up in a blog post.

I’m not going to go over the basics, because I think the Spotify application does a pretty good job at explaining itself. If you’re new to Spotify, just play with it for an hour or two, and you should get the hang of it.

Done? Great!

Sharing playlists

Like most other things in Spotify, playlists have URIs. What this means, is that you can right-click on any of your playlists and select “Copy HTTP Link” or “Copy Spotify URI”, and you’ll get something you can paste on your blog, in an e-mail or chat message, or pretty much anywhere else. It works just like a link to a website, except it points to a playlist in Spotify.

Anyone who comes across one of these URIs can either click on it, or paste it into the search box in the Spotify application. Now, they too will be able to listen to your playlist, but they won’t be able to make any changes to it.

If you want that to happen, right-click on the playlist and select “Collaborative Playlist”. This is great for making playlists with your friends! Just remember that anyone who knows the URI of your playlist will be able to add or remove tracks to it now.

The Inbox

There is a special kind of collaborative playlist, which as far as I know was first seen here, and that is The Inbox.

From a technical point of view, there is nothing special about The Inbox. It’s simply a playlist which is called “Inbox” and marked as collaborative.

The idea behind it, however, is that you give the URI for it to all your friends (and, if you’re adventurous, complete strangers), and ask them to put music they think you might like in it. Sure, you might get the occasional spam track, but usually it works great. You should make one for yourself!

Here is my Spotify Inbox!

Last.fm

Last.fm is not directly related to Spotify, and is quite a bit older, but is awesome nonetheless.

Basically, it’s a website that keeps track of all the music you listen to, and creates a profile for you based on that. And this is where the magic starts. Not only can you get nice charts of your listening statistics, but also recommendations for music you might like and reminders for concerts and so much more. It can be a little iffy at first, but once you’ve scrobbled enough tracks, it really gets spot on.

And you can make it be the chocolate to Spotify’s peanut butter.

First off, you need to sign up for a Last.fm account. Once you’ve done that, go to the Preferences view in the Spotify application, and look for the Last.fm section. Here, make sure “Enable scrobbling to Last.fm” is checked, and put your Last.fm username and password in their respective fields.

And then just listen to music.

Here is my Last.fm Profile!