-
-
Save mt3/882272 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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