Skip to content

Instantly share code, notes, and snippets.

@brenes
Created March 22, 2011 21:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save brenes/882063 to your computer and use it in GitHub Desktop.
Save brenes/882063 to your computer and use it in GitHub Desktop.
SImple and nasty song recommender for lastfm
# This script just get the latest tracks of your friends on Last.fm and recommends those more popular.
# It's all based on a conversation between @mort, @rochgs, @littlemove and me (mainly by @mort)
# INSTRUCTIONS
# 1. Install lastfm gem: https://github.com/youpy/ruby-lastfm/
# gem install lastfm
# 2. Get a Last.fm API Key on http://www.lastfm.es/api
require 'lastfm'
api_key = "GET YOURS"
api_secret = "GET YOURS"
lastfm = Lastfm.new(api_key, api_secret)
friends = lastfm.user.get_friends("A USERNAME")
songs = {}
friends.each do |friend|
puts "getting songs for #{friend["name"]}"
lastfm.user.get_recent_tracks(friend["name"], 100).each do |song|
songs["#{song["name"]} - #{song["artist"]["content"]}"] ||= 0
songs["#{song["name"]} - #{song["artist"]["content"]}"] += 1
end
end
ordered_songs = {}
songs.each do |name, times|
ordered_songs[times] ||= []
ordered_songs[times] << name
end
ordered_songs.keys.sort.each do |times|
puts "\n#{times} ------------------------------------- "
ordered_songs[times].each do |song| puts "\t\t#{song}" end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment