Rockstar Build Status Gem Version

Rockstar is a wrapper for the audioscrobbler web services ( This gem is based on the scrobbler gem by John Nunemaker and was updated to use the 2.0 version of the api

Below is just a sampling of how easy this lib is to use.

Please initialize your api key and secret before using the api:

Rockstar.lastfm = YAML.load_file('lastfm.yml')

Here is an example lastfm.yml:

api_key: "API"
api_secret: "SECRET"

If you want to use the api in an rails app, you could add an initializer in config/initializers/lastm.rb and load a config/lastfm.yml file.

rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
Rockstar.lastfm =  YAML.load_file(rails_root + '/config/lastfm.yml')

Alternatively you can provide a hash with the api key and secret:

Rockstar.lastfm = {:api_key => "API", :api_secret => "SECRET"}


user ='jnunemaker')

puts "#{user.username}'s Recent Tracks"
puts "=" * (user.username.length + 16)
user.recent_tracks.each { |t| puts }


puts "#{user.username}'s Top Tracks"
puts "=" * (user.username.length + 13)
user.top_tracks.each { |t| puts "(#{t.playcount}) #{}" }


album ='Carrie Underwood', 'Some Hearts', :include_info => true)

puts "Album: #{}"
puts "Artist: #{album.artist}"
puts "URL: #{album.url}"
puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"


If you want to load all informations about an artist or any other object, you have to add :include_info => true .

artist ='Carrie Underwood', :include_info => true)

puts artist.url

puts 'Top Tracks'
puts "=" * 10
artist.top_tracks.each { |t| puts "(#{}" }


puts 'Similar Artists'
puts "=" * 15
artist.similar.each { |a| puts "(#{a.match}%) #{}" }


tag ='country')

puts 'Top Albums'
tag.top_albums.each { |a| puts "(#{a.count}) #{} by #{a.artist}" }


puts 'Top Tracks'
tag.top_tracks.each { |t| puts "(#{t.count}) #{} by #{t.artist}" }


geo =

# Get events for a lat/long => 50.0, :long => 12.3).each{|e| p "#{e.title} at #{}"}

# Get events for a location => 'london').each{|e| p "#{e.title} at #{}"}

# To get a list of possible locations use
geo.metros("germany").each{|m| p}

# Retrieve list of top tracks by country
geo.toptracks('united kingdom', 10).each{|t| p "#{} by #{t.artist}"}

# Retrieve list of top artists by country
geo.topartists('united kingdom', 10).each{|a| p "artist #{} with #{a.listenercount} listeners"}


# Get artists and albums for user
library =

puts 'Artists'
library.artists(false, :user => 'jnunemaker').each { |a| puts }

puts 'Albums'
library.albums(false, :user => 'jnunemaker').each { |a| puts }

# Get it with Rockstar::User
user ='jnunemaker')

puts 'Artists'
user.artists.each { |a| puts }

puts 'Albums'
user.albums.each { |a| puts }

Get rights to access the user data for scrobbing, now playing, events etc...

a =
token = a.token

puts "Please open{Rockstar.lastfm_api_key}&token=#{token}"
puts "Press enter when done."


session = a.session(token)

You can store the session.key somewhere and use it from now on to identify the user. More details can be found in Rockstar::Auth or examples/scrobble.rb


track ='Carrie Underwood', 'Before He Cheats')
puts 'Fans'
puts "=" * 4 { |u| puts "(#{u.weight}) #{u.username}" }


track ='Carrie Underwood', 'Before He Cheats')
track.scrobble(, session.key)

Now Playing Submission

track ='Carrie Underwood', 'Before He Cheats')
track.updateNowPlaying(, session.key)

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.


Copyright (c) 2007-2011 John Nunemaker, Bodo "Bitboxer" Tasche, Nick "zapnap" Plante. See LICENSE for details.


Thanks to for sponsering the work on the rockstar gem.