Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 32 lines (24 sloc) 985 Bytes
#!/usr/bin/env jruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
require 'rubygems'
gem 'spotify-api'
require 'clients/lastfm'
require 'clients/spotify'
# a demo app which grabs tracks from last.fm and creates a spotify
# playlist based on friends loved tracks
if __FILE__ == $0
username = ARGV.shift or raise "#{$0} <username>"
puts "fetching last.fm tracks (friends/recently_loved)"
limit = 10 # 10 tracks per friend
tracks = LastFM.friends_loved_tracks(username, limit).values.flatten
puts "resolving spotify ids"
spotify_tracks = begin
Spotify.resolve(tracks.map {|t| [t["title"], t["artist"]] })
rescue Errno::ECONNREFUSED
fail "Could not connect to spotify-api server. Make sure it it running."
end
if spotify_tracks.size > 0
puts "creating playlist with #{spotify_tracks.size} tracks"
puts Spotify.create_playlist("loved by friends of #{username}", spotify_tracks.map { |t| t['id'] })
end
end